-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathserver.tsx
41 lines (35 loc) · 984 Bytes
/
server.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import React from "react"
import ReactDOMServer from "react-dom/server"
import express from "express"
import webpack from "webpack"
import webpackDevMiddleware from "webpack-dev-middleware"
import webpackConfig from "../webpack.config"
import { mediaStyles } from "./Media"
import { App } from "./App"
const compiler = webpack(webpackConfig)
const app = express()
app.use(
webpackDevMiddleware(compiler, {
publicPath: webpackConfig.output.publicPath,
serverSideRender: true,
stats: "errors-only",
})
)
app.get("/", (_req, res) => {
const html = ReactDOMServer.renderToString(<App />)
res.send(`
<html>
<head>
<title>@artsy/fresnel | SSR Example</title>
<style type="text/css">${mediaStyles}</style>
</head>
<body>
<div id="root">${html}</div>
<script src="/assets/app.js"></script>
</body>
</html>
`)
})
app.listen(3000, () => {
console.warn("\nApp started at http://localhost:3000 \n")
})