Jaime Ramírez
2020-06-03 728f86ac06d0102625c6af2b75e923228ad9ddac
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
42
/*
Code to serve the web app in PRODUCTION.
Injects environment variables at runtime in build/index.html
*/
 
const express = require("express");
const path = require("path");
const fs = require("fs");
const app = express();
 
app.use(express.static(path.join(__dirname, "build")));
 
app.get("/*", function (req, res) {
    const indexFilePath = path.join(__dirname, "build", "index.html");
    fs.readFile(indexFilePath, (_, content) => {
        const html = content.toString()
            .replace(
                "{{REACT_APP_ADOPTION_SERVICE_URL}}",
                process.env.REACT_APP_ADOPTION_SERVICE_URL || ""
            )
            .replace(
                "{{REACT_APP_ANIMAL_SERVICE_URL}}",
                process.env.REACT_APP_ANIMAL_SERVICE_URL || ""
            )
            .replace(
                "{{REACT_APP_SHELTER_SERVICE_URL}}",
                process.env.REACT_APP_SHELTER_SERVICE_URL || ""
            )
            .replace(
                "{{REACT_APP_NEWS_SERVICE_URL}}",
                process.env.REACT_APP_NEWS_SERVICE_URL || ""
            )
            .replace(
                "{{REACT_APP_NEWS_ENABLED}}",
                process.env.REACT_APP_NEWS_ENABLED || ""
            );
 
        res.send(html);
    });
});
 
app.listen(process.env.PORT || 3000);