diff --git a/package.json b/package.json index afe6793..25ce917 100644 --- a/package.json +++ b/package.json @@ -30,5 +30,8 @@ "last 1 firefox version", "last 1 safari version" ] + }, + "devDependencies": { + "express": "^4.17.1" } } diff --git a/public/index.html b/public/index.html index aa069f2..14c86cf 100644 --- a/public/index.html +++ b/public/index.html @@ -7,7 +7,15 @@ + + - React App + __TITLE__ diff --git a/server.js b/server.js new file mode 100644 index 0000000..3d4f317 --- /dev/null +++ b/server.js @@ -0,0 +1,43 @@ +const express = require("express"); +const path = require("path"); +const fs = require("fs"); + +const PORT = process.env.PORT || 5000; + +const app = express(); + +app.get("/", (req, res) => { + const filePath = path.resolve(__dirname, "./build", "index.html"); + fs.readFile(filePath, "utf8", (err, data) => { + if (err) { + return console.log(err); + } + + data = data + .replace(/__TITLE__/g, "Home Page") + .replace(/__DESCRIPTION__/g, "Home page description."); + + res.send(data) + }); +}); + +app.get("/about", (req, res) => { + const filePath = path.resolve(__dirname, "./build", "index.html"); + fs.readFile(filePath, "utf8", (err, data) => { + if (err) { + return console.log(err); + } + + data = data + .replace(/__TITLE__/g, "About Page") + .replace(/__DESCRIPTION__/g, "About page description."); + + res.send(data) + }); +}); + +app.use(express.static(path.resolve(__dirname, "./build"))) + +app.listen(PORT, () => { + console.log(`Server is listening on port ${PORT}`) +})