Created
October 13, 2015 15:32
-
-
Save philippTheCat/c2362c46f9c22c825bcc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
import express from "express"; | |
var routes = require("./common"); | |
var app = express() | |
import { renderToString } from 'react-dom/server' | |
import { match, RoutingContext } from 'react-router' | |
var React = require("react"); | |
var StateLoader = require("./lib/StateLoader"); | |
import { createMemoryHistory } from 'history' | |
const history = createMemoryHistory(); | |
var alt = require("./alt"); | |
app.use('/', function(req, res){ | |
console.log("==="); | |
const location = history.createLocation(req.url); | |
match({ routes, location: location }, (error, redirectLocation, renderProps) => { | |
if (error) { | |
res.status(500).send(error.message) | |
} else if (redirectLocation) { | |
res.redirect(302, redirectLocation.pathname + redirectLocation.search) | |
} else if (renderProps) { | |
StateLoader.loadPrerenderStateFromServer(); | |
console.log(alt); | |
res.status(200).send(renderToString(<RoutingContext {...renderProps} />)) | |
console.log("rendered") | |
} else { | |
res.send(404, 'Not found') | |
} | |
}) | |
console.log("+++"); | |
}); | |
app.listen(3333) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment