1
+ import "babel-polyfill" ;
2
+
1
3
import express , { Request , Response } from "express" ;
2
4
import React from "react" ;
3
5
import ReactDOMServer from "react-dom/server" ;
@@ -6,6 +8,7 @@ import { getBundles, IReactLoadableWebpackBundle } from "react-loadable/webpack"
6
8
import { Provider } from "react-redux" ;
7
9
import { matchPath , StaticRouter } from "react-router" ;
8
10
11
+ import { setApiUrls } from "../universal/actions" ;
9
12
import App from "../universal/app" ;
10
13
import { IState } from "../universal/models" ;
11
14
import { routes } from "../universal/routes" ;
@@ -15,12 +18,24 @@ const stats = require("./reactLoadable.json");
15
18
const app = express ( ) ;
16
19
17
20
app . use ( "/client" , express . static ( "client" ) ) ;
21
+
22
+ app . use ( "/api/description" , function ( req , res ) {
23
+ res . setHeader ( "Content-Type" , "application/json" ) ;
24
+ setTimeout ( ( ) => res . send ( JSON . stringify ( { description : "Description response" } ) ) , 1000 ) ;
25
+ } ) ;
26
+
18
27
app . use ( handleRender ) ;
19
28
20
29
function handleRender ( req : Request , res : Response ) {
21
30
const promises : Promise < any > [ ] = [ ] ;
22
31
const store = createStore ( ) ;
23
32
33
+ store . dispatch (
34
+ setApiUrls ( {
35
+ descriptionUrl : `${ req . protocol } ://${ req . get ( "host" ) } /api/description`
36
+ } )
37
+ ) ;
38
+
24
39
routes . some ( route => {
25
40
const match = matchPath ( req . path , route ) ;
26
41
if ( match && route . fetchData ) {
0 commit comments