-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
37 lines (33 loc) · 1019 Bytes
/
server.js
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
import express from 'express';
import React from 'React';
import path from 'path';
import App from './src/components/app';
import { renderToString } from "react-dom/server";
import { StaticRouter } from "react-router-dom";
import fs from 'fs';
const app = express();
const port = 3000;
app.use(express.static(path.resolve('dist')));
app.get('/*', (req,res) => {
const context = { };
const app = renderToString(
<StaticRouter context={ context } location={ req.url }>
<App />
</StaticRouter>
);
return res.send( `<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Mercado libre test</title>
<link rel="stylesheet" type="text/css" href="/css/style.css">
</head>
<body>
<div id="app">${app}</div>
<script src="/1.bundle.js"></script>
<script src="/bundle.js"></script>
</body>
</html>
`);
});
app.listen(port, () => console.log(`Mercado libre test is listening on port ${port}!`))