-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (35 loc) · 1 KB
/
index.js
File metadata and controls
43 lines (35 loc) · 1 KB
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
43
import http from "http";
import express from "express";
import cors from "cors";
import { getIpNumber } from "./ip.js";
import { data } from "./data.js";
const app = express();
const server = http.createServer(app);
app.use(cors());
app.get("/api", (req, res) => {
res.json(data);
});
app.use("/", (req, res, next) => {
console.log(`Requisição recebida: ${req.url}`);
res.send("Esse é um simples servidor para enviar dados, simulando uma API");
});
server.listen(4040, "0.0.0.0", () => {
console.log(`Servidor rodando em http://${getIpNumber()}:4040`);
});
process.on("SIGTERM", shutDown);
process.on("SIGINT", shutDown);
process.on("exit", shutDown);
process.on("uncaughtException", (err, origin) =>{
console.log("Erro não tratado: ", err, origin);
server.close(() => {
console.log("Servidor encerrado");
process.exit(0);
});
});
function shutDown() {
console.log("Encerrando...");
server.close(() => {
console.log("Servidor encerrado");
process.exit(0);
});
};