You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.4 KiB
53 lines
1.4 KiB
import App from './App'; |
|
import React from 'react'; |
|
import { StaticRouter } from 'react-router-dom'; |
|
import express from 'express'; |
|
import { renderToString } from 'react-dom/server'; |
|
|
|
const assets = require(process.env.RAZZLE_ASSETS_MANIFEST); |
|
|
|
const server = express(); |
|
server |
|
.disable('x-powered-by') |
|
.use(express.static(process.env.RAZZLE_PUBLIC_DIR)) |
|
.get('/*', (req, res) => { |
|
const context = {}; |
|
const markup = renderToString( |
|
<StaticRouter context={context} location={req.url}> |
|
<App /> |
|
</StaticRouter> |
|
); |
|
|
|
if (context.url) { |
|
res.redirect(context.url); |
|
} else { |
|
res.status(200).send( |
|
`<!doctype html> |
|
<html lang=""> |
|
<head> |
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> |
|
<meta charset="utf-8" /> |
|
<title>Tanner Collin</title> |
|
<meta name="viewport" content="width=device-width, initial-scale=1"> |
|
<link rel="stylesheet" href="reset.css"> |
|
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet"> |
|
${ |
|
assets.client.css |
|
? `<link rel="stylesheet" href="${assets.client.css}">` |
|
: '' |
|
} |
|
${ |
|
process.env.NODE_ENV === 'production' |
|
? `<script src="${assets.client.js}" defer></script>` |
|
: `<script src="${assets.client.js}" defer crossorigin></script>` |
|
} |
|
</head> |
|
<body> |
|
<div id="root">${markup}</div> |
|
</body> |
|
</html>` |
|
); |
|
} |
|
}); |
|
|
|
export default server;
|
|
|