-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.js
33 lines (25 loc) · 791 Bytes
/
app.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
import serverless from "serverless-http";
import express from "express";
import cors from "cors";
import bodyParser from "body-parser";
import React from "react";
import { renderToString } from "react-dom/server";
import App from "./src/App";
import Data from "./src/users";
import fs from "fs";
import path from "path";
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.resolve(__dirname, "./Browser")));
const markup = fs.readFileSync(__dirname + "/index.html",
"utf8"
);
app.get("**", (req, res) => {
Data().then(users => {
const html = renderToString(<App data={users} />);
res.send(markup.replace("<!--App-->", html));
});
});
module.exports.ssr = serverless(app);