-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (28 loc) · 879 Bytes
/
server.js
File metadata and controls
35 lines (28 loc) · 879 Bytes
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
const path = require("path");
const fs = require("fs");
const express = require("express");
const helmet = require("helmet");
const app = express();
const PORT = process.env.PORT || 3000;
const buildPath = path.join(__dirname, "dist/");
//si la carpeta no existe para ejecución
if (!fs.existsSync(buildPath)) {
throw new Error("Build the project first");
}
app.use(helmet());
// Handle client routing, return all requests to the app
app.get("*", (_req, res, next) => {
try {
res.send("Site Under construction");
//res.sendFile(path.join(__dirname, path.normalize("dist/index.html")));
} catch (error) {
next(error);
}
});
app.use((error, req, res) => {
console.error("Erro del server ", error);
res.status(500).send({ error: "Error Contact Admin" });
});
app.listen(PORT, () => {
console.log(`Server listening at http://localhost:${PORT}`);
});