WIP

Seto Elkahfi committed Jul 31, 2023 at 18:15 UTC b4972742a6bf2a16dabb40fc528f7dbfc786a8d2
4 files changed +44 -6
package-lock.json
+2
@@ -17,6 +17,7 @@
17 "axios": "^0.25.0",
18 "bootstrap": "5.1.3",
19 "dexie": "^3.2.0",
20 + "express": "^4.18.2",
21 "firebase": "^8.6.2",
22 "react": "^16.14.0",
23 "react-bootstrap": "^2.1.1",
@@ -31,6 +32,7 @@
32 "typescript": "^4.0.0"
33 },
34 "devDependencies": {
35 + "@types/express": "^4.17.17",
36 "@types/react-intl": "^3.0.0"
37 }
38 },
package.json
+7 -4
@@ -12,6 +12,7 @@
12 "axios": "^0.25.0",
13 "bootstrap": "5.1.3",
14 "dexie": "^3.2.0",
15 + "express": "^4.18.2",
16 "firebase": "^8.6.2",
17 "react": "^16.14.0",
18 "react-bootstrap": "^2.1.1",
@@ -26,10 +27,11 @@
27 "typescript": "^4.0.0"
28 },
29 "scripts": {
29 - "start": "PORT=3002 react-scripts start",
30 - "build": "react-scripts build",
31 - "test": "react-scripts test",
32 - "eject": "react-scripts eject"
30 + "client:start": "PORT=3002 react-scripts start",
31 + "client:build": "react-scripts build",
32 + "client:test": "react-scripts test",
33 + "eject": "react-scripts eject",
34 + "server:start": "node server/server.js"
35 },
36 "eslintConfig": {
37 "extends": "react-app"
@@ -41,6 +43,7 @@
43 "not op_mini all"
44 ],
45 "devDependencies": {
46 + "@types/express": "^4.17.17",
47 "@types/react-intl": "^3.0.0"
48 }
49 }
server/index.tsx new
+33
@@ -0,0 +1,33 @@
1 +import path from "path";
2 +import fs from "fs";
3 +
4 +import React from "react";
5 +import ReactDOMServer from "react-dom/server";
6 +import express from "express";
7 +
8 +const PORT = process.env.PORT || 3000;
9 +const app = express();
10 +
11 +app.get("/", (req, res) => {
12 + fs.readFile(path.resolve("./public/index.html"), "utf8", (err, data) => {
13 + if (err) {
14 + console.error(err);
15 + return res.status(500).send("An error occurred");
16 + }
17 +
18 + return res.send(
19 + data.replace(
20 + '<div id="root"></div>',
21 + `<div id="root">${ReactDOMServer.renderToString(<App />)}</div>`
22 + )
23 + );
24 + });
25 +});
26 +
27 +app.use(
28 + express.static(path.resolve(__dirname, ".", "dist"), { maxAge: "30d" })
29 +);
30 +
31 +app.listen(PORT, () => {
32 + console.log(`Server is listening on port ${PORT}`);
33 +});
\ No newline at end of file
yarn.lock
+2 -2
@@ -2200,7 +2200,7 @@
2200 "@types/range-parser" "*"
2201 "@types/send" "*"
2202
2203 -"@types/express@*", "@types/express@^4.17.13":
2203 +"@types/express@*", "@types/express@^4.17.13", "@types/express@^4.17.17":
2204 version "4.17.17"
2205 resolved "https://registry.npmjs.org/@types/express/-/express-4.17.17.tgz"
2206 integrity sha512-Q4FmmuLGBG58btUnfS1c1r/NQdlp3DMfGDGig8WhfpA2YRUtEkxAjkZb0yvplJGYdF1fsQ81iMDcH24sSCNC/Q==
@@ -4733,7 +4733,7 @@ expect@^27.5.1:
4733 jest-matcher-utils "^27.5.1"
4734 jest-message-util "^27.5.1"
4735
4736 -express@^4.17.3:
4736 +express@^4.17.3, express@^4.18.2:
4737 version "4.18.2"
4738 resolved "https://registry.npmjs.org/express/-/express-4.18.2.tgz"
4739 integrity sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==