| 
									
										
										
										
											2016-08-18 11:41:13 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * app.js | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-09-25 15:01:06 +02:00
										 |  |  |  * This is the entry file for the application when running the build | 
					
						
							| 
									
										
										
										
											2016-08-18 11:41:13 +02:00
										 |  |  |  * code. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-11-11 22:14:05 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* eslint-disable */ | 
					
						
							| 
									
										
										
										
											2016-08-18 11:41:13 +02:00
										 |  |  | import 'babel-polyfill'; | 
					
						
							| 
									
										
										
										
											2018-09-25 15:01:06 +02:00
										 |  |  | import { findIndex } from 'lodash'; | 
					
						
							| 
									
										
										
										
											2017-08-18 14:17:15 +02:00
										 |  |  | import 'sanitize.css/sanitize.css'; | 
					
						
							| 
									
										
										
										
											2017-09-09 15:49:59 +02:00
										 |  |  | import 'whatwg-fetch'; | 
					
						
							| 
									
										
										
										
											2018-01-17 12:58:14 +01:00
										 |  |  | import { | 
					
						
							| 
									
										
										
										
											2018-09-25 17:11:14 +02:00
										 |  |  |   getAppPluginsSucceeded, | 
					
						
							| 
									
										
										
										
											2018-01-17 12:58:14 +01:00
										 |  |  |   unsetHasUserPlugin, | 
					
						
							| 
									
										
										
										
											2019-02-22 10:05:07 +01:00
										 |  |  | } from './containers/App/actions'; | 
					
						
							| 
									
										
										
										
											2018-09-25 15:01:06 +02:00
										 |  |  | import { basename, store } from './createStore'; | 
					
						
							|  |  |  | import './intlPolyfill'; | 
					
						
							|  |  |  | import './public-path'; | 
					
						
							|  |  |  | import './strapi'; | 
					
						
							| 
									
										
										
										
											2018-01-17 12:58:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-25 15:01:06 +02:00
										 |  |  | const dispatch = store.dispatch; | 
					
						
							| 
									
										
										
										
											2016-08-18 11:41:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-02 19:36:09 +01:00
										 |  |  | // Don't inject plugins in development mode.
 | 
					
						
							|  |  |  | if (window.location.port !== '4000') { | 
					
						
							| 
									
										
										
										
											2019-01-30 13:25:08 +01:00
										 |  |  |   fetch(`${strapi.remoteURL}/config/plugins.json`, { cache: 'no-cache' }) | 
					
						
							| 
									
										
										
										
											2017-11-02 19:36:09 +01:00
										 |  |  |     .then(response => { | 
					
						
							|  |  |  |       return response.json(); | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     .then(plugins => { | 
					
						
							| 
									
										
										
										
											2018-09-25 17:11:14 +02:00
										 |  |  |       dispatch(getAppPluginsSucceeded(plugins)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-07 19:12:20 +01:00
										 |  |  |       if (findIndex(plugins, ['id', 'users-permissions']) === -1) { | 
					
						
							| 
									
										
										
										
											2018-09-25 17:11:14 +02:00
										 |  |  |         dispatch(unsetHasUserPlugin()); | 
					
						
							| 
									
										
										
										
											2017-12-07 19:12:20 +01:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-12-06 11:58:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-16 16:18:33 +01:00
										 |  |  |       const $body = document.getElementsByTagName('body')[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-02 19:36:09 +01:00
										 |  |  |       (plugins || []).forEach(plugin => { | 
					
						
							|  |  |  |         const script = document.createElement('script'); | 
					
						
							| 
									
										
										
										
											2017-11-28 12:40:39 +01:00
										 |  |  |         script.type = 'text/javascript'; | 
					
						
							|  |  |  |         script.onerror = function (oError) { | 
					
						
							|  |  |  |           const source = new URL(oError.target.src); | 
					
						
							| 
									
										
										
										
											2018-01-16 16:18:33 +01:00
										 |  |  |           const url = new URL(`${strapi.remoteURL}`); | 
					
						
							| 
									
										
										
										
											2017-11-28 12:40:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |           if (!source || !url) { | 
					
						
							|  |  |  |             throw new Error(`Impossible to load: ${oError.target.src}`); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           // Remove tag.
 | 
					
						
							|  |  |  |           $body.removeChild(script); | 
					
						
							| 
									
										
										
										
											2017-12-01 15:45:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 12:40:39 +01:00
										 |  |  |           // New attempt with new src.
 | 
					
						
							|  |  |  |           const newScript = document.createElement('script'); | 
					
						
							|  |  |  |           newScript.type = 'text/javascript'; | 
					
						
							|  |  |  |           newScript.src = `${url.origin}${source.pathname}`; | 
					
						
							|  |  |  |           $body.appendChild(newScript); | 
					
						
							|  |  |  |         }; | 
					
						
							| 
									
										
										
										
											2017-11-02 19:36:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-09 18:39:50 +01:00
										 |  |  |         script.src = plugin.source[process.env.NODE_ENV].indexOf('://') === -1 ? | 
					
						
							|  |  |  |           `${basename}${plugin.source[process.env.NODE_ENV]}`.replace('//', '/'): // relative
 | 
					
						
							|  |  |  |           plugin.source[process.env.NODE_ENV]; // absolute
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 12:40:39 +01:00
										 |  |  |         $body.appendChild(script); | 
					
						
							| 
									
										
										
										
											2017-11-02 19:36:09 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     .catch(err => { | 
					
						
							| 
									
										
										
										
											2018-08-08 17:27:47 +02:00
										 |  |  |       console.log(err); // eslint-disable-line no-console
 | 
					
						
							| 
									
										
										
										
											2017-11-02 19:36:09 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-30 18:25:04 +02:00
										 |  |  | export { | 
					
						
							|  |  |  |   dispatch, | 
					
						
							| 
									
										
										
										
											2016-10-05 11:32:31 +02:00
										 |  |  | }; |