1- const React = require ( 'react' ) ;
21const ReactDOM = require ( 'react-dom/server' ) ;
32// const 'isomorphic-fetch';
43const addCookie = require ( '../utils/addCookie' ) ;
@@ -16,11 +15,14 @@ module.exports = function createAppOnServer(config) {
1615 return ( req , res ) => {
1716 // try to find locale from url, header and cookies
1817 const localeFromUrl = getLocaleFromUrl ( req . originalUrl , config . app . locale . supported ) ;
19- const localeFromHeader = getLocaleFromHeader ( req . headers [ 'accept-language' ] , config . app . locale . supported ) ;
18+ const localeFromHeader = getLocaleFromHeader (
19+ req . headers [ 'accept-language' ] ,
20+ config . app . locale . supported
21+ ) ;
2022 const localeFromCookies = getLocaleFromCookies ( req . cookies , config . app . locale . supported ) ;
2123
2224 const url = req . url ;
23- const urlWithoutLocale = ( localeFromUrl )
25+ const urlWithoutLocale = localeFromUrl
2426 ? stripLocaleFromUrl ( req . originalUrl , localeFromUrl )
2527 : req . originalUrl ;
2628
@@ -38,7 +40,7 @@ module.exports = function createAppOnServer(config) {
3840 addCookie ( req , res , {
3941 name : 'lang' ,
4042 value : locale ,
41- options : { maxAge : 2628000 * 60 * 1000 } // 5 years lifetime
43+ options : { maxAge : 2628000 * 60 * 1000 } , // 5 years lifetime
4244 } ) ;
4345 }
4446
@@ -57,7 +59,7 @@ module.exports = function createAppOnServer(config) {
5759 addCookie ( req , res , {
5860 name : 'csrf' ,
5961 value : csrfToken ,
60- options : { httpOnly : true }
62+ options : { httpOnly : true } ,
6163 } ) ;
6264 }
6365
@@ -82,15 +84,17 @@ module.exports = function createAppOnServer(config) {
8284 if ( process . env . APP_MODE === 'development' ) {
8385 delete require . cache [ paths . webpackAssets ] ;
8486
85- Object . keys ( require . cache ) . forEach ( function ( id ) {
86- if ( / [ \ /\\ ] a p p [ \ /\\ ] / . test ( id ) ) delete require . cache [ id ] ;
87+ Object . keys ( require . cache ) . forEach ( id => {
88+ if ( / [ / \\ ] a p p [ / \\ ] / . test ( id ) ) delete require . cache [ id ] ;
8789 } ) ;
8890 }
8991
9092 // define render, redirect and error function for hydrate function
9193 const render = ( component , data ) => {
94+ // eslint-disable-next-line
9295 const assets = require ( paths . webpackAssets ) ;
9396 const content = component ? ReactDOM . renderToString ( component ) : '' ;
97+ // eslint-disable-next-line
9498 const renderHtml = require ( paths . appHtml ) . default ;
9599
96100 const htmlSnippets = generateHtmlSnippets ( meta , content , assets , data , config . devBuild . dll ) ;
@@ -99,15 +103,15 @@ module.exports = function createAppOnServer(config) {
99103
100104 res . status ( 200 ) . send ( html ) ;
101105 } ;
102- const redirect = ( path ) => {
106+ const redirect = path => {
103107 res . redirect ( path ) ;
104- }
105- const error = ( message , status ) => {
108+ } ;
109+ const error = message => {
106110 res . status ( 404 ) ;
107111 if ( message ) {
108- res . send ( message )
112+ res . send ( message ) ;
109113 }
110- }
114+ } ;
111115
112116 // Render page on client if server side rendering is disabled.
113117 // Initial state should be empty in this case.
@@ -117,7 +121,8 @@ module.exports = function createAppOnServer(config) {
117121 }
118122
119123 // get hydrate function and hydrate
124+ // eslint-disable-next-line
120125 const hydrate = require ( paths . appServerEntry ) . default ;
121126 hydrate ( meta , { error, redirect, render } ) ;
122127 } ;
123- } ;
128+ } ;
0 commit comments