3
3
*/
4
4
import express from 'express'
5
5
import path from 'path'
6
-
7
- import React from 'react'
8
- import { renderToString } from 'react-dom/server'
9
-
10
- import Component from '../client/pages/example/App'
11
- import extractMapping from './middleware/extractMapping'
12
- import mapAssets from './utils/mapAssets'
13
- import { StaticRouter } from 'react-router'
14
-
15
- import { Provider } from 'react-redux'
16
- import store from '../client/pages/tools/store/forServer'
17
- import { Content } from '../client/pages/integration/Root/index'
18
- import Integration from '../client/pages/integration/App'
19
- import reducers from '../client/pages/integration/store/'
6
+ import pages from './routes/pages'
20
7
const app = express ( )
21
8
app . set ( 'views' , path . join ( __dirname , 'views' ) ) ;
22
9
app . set ( 'view engine' , 'hbs' )
23
- app . use ( express . static ( path . resolve ( __dirname , '../public' ) ) )
10
+ app . get ( express . static ( path . resolve ( __dirname , '../public' ) ) )
24
11
25
12
if ( process . env . NODE_ENV === 'local' ) {
26
13
const config = require ( '../webpack.config.local' )
@@ -38,37 +25,18 @@ if (process.env.NODE_ENV === 'local') {
38
25
serverSideRender : true
39
26
} ) )
40
27
}
41
-
42
- //以路径名称作为页面区分
43
- app . use ( '/Components' , extractMapping , ( req , res , next ) => {
44
- //可以根据路径,针对某一个页面进行服务端渲染
45
- const content = renderToString ( < StaticRouter
46
- location = { req . url }
47
- context = { { } }
48
- basename = "/components" >
49
- < Component />
50
- </ StaticRouter > )
51
- res . render ( 'components' , {
52
- app : content ,
53
- links : mapAssets ( 'components/index.css' ) ,
54
- scripts : mapAssets ( 'components/index.js' )
28
+ //页面链式路由入口
29
+ app . use ( '/p' , pages )
30
+ //首页
31
+ app . get ( '/' , ( req , res ) => {
32
+ res . render ( 'homepage' , {
33
+ title : 'react-redux-iapp同构项目'
55
34
} )
56
35
} )
57
-
58
- app . use ( '/integration' , extractMapping , ( req , res , next ) => {
59
- const content = renderToString ( < Provider store = { store ( reducers ) } >
60
- < StaticRouter
61
- location = { req . url }
62
- context = { { } }
63
- basename = "/integration"
64
- >
65
- < Content component = { Integration } />
66
- </ StaticRouter >
67
- </ Provider > )
68
- res . render ( 'integration' , {
69
- app : content ,
70
- links : mapAssets ( 'integration/index.css' ) ,
71
- scripts : mapAssets ( 'integration/index.js' )
36
+ app . use ( ( req , res , next , err ) => {
37
+ res . json ( {
38
+ message : '404' ,
39
+ err : err
72
40
} )
73
41
} )
74
42
export default app
0 commit comments