mirror of
https://github.com/Lomanic/presence-button-web
synced 2024-11-26 07:27:30 +00:00
💶😻 Checkpoint
./server.js:933874/5449
This commit is contained in:
parent
207e3c7677
commit
13859b2965
10
server.js
10
server.js
@ -13,15 +13,12 @@ try {
|
|||||||
const express = require("express");
|
const express = require("express");
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
// http://expressjs.com/en/starter/static-files.html
|
|
||||||
app.use(express.static("public"));
|
app.use(express.static("public"));
|
||||||
|
|
||||||
// http://expressjs.com/en/starter/basic-routing.html
|
|
||||||
app.get("/", (req, res) => {
|
app.get("/", (req, res) => {
|
||||||
res.sendFile(__dirname + "/views/index.html");
|
res.sendFile(__dirname + "/views/index.html");
|
||||||
});
|
});
|
||||||
|
|
||||||
// http://expressjs.com/en/starter/basic-routing.html
|
|
||||||
app.get("/img", (req, res) => {
|
app.get("/img", (req, res) => {
|
||||||
if (fuzIsOpen && new Date() - 2 * 60 * 1000 < lastSeen) {
|
if (fuzIsOpen && new Date() - 2 * 60 * 1000 < lastSeen) {
|
||||||
return res.sendFile(__dirname + "/views/open.svg"); // https://www.flaticon.com/free-icon/open_1234189
|
return res.sendFile(__dirname + "/views/open.svg"); // https://www.flaticon.com/free-icon/open_1234189
|
||||||
@ -37,7 +34,6 @@ app.get("/api", (req, res) => {
|
|||||||
res.send({ fuzIsOpen, lastSeen });
|
res.send({ fuzIsOpen, lastSeen });
|
||||||
});
|
});
|
||||||
|
|
||||||
// http://expressjs.com/en/starter/basic-routing.html
|
|
||||||
app.get("/status", (req, res) => {
|
app.get("/status", (req, res) => {
|
||||||
// http basic auth handling without 3rd-party lib https://stackoverflow.com/a/33905671
|
// http basic auth handling without 3rd-party lib https://stackoverflow.com/a/33905671
|
||||||
const auth = {
|
const auth = {
|
||||||
@ -73,10 +69,12 @@ const listener = app.listen(process.env.PORT, function() {
|
|||||||
console.log("Your app is listening on port " + listener.address().port);
|
console.log("Your app is listening on port " + listener.address().port);
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on("SIGTERM", function() {
|
if (process.env.PROJECT_DOMAIN != "") {
|
||||||
|
process.on("SIGTERM", function() {
|
||||||
console.log("SIGTERM received, sending SOS to Resurrect...");
|
console.log("SIGTERM received, sending SOS to Resurrect...");
|
||||||
require("https").get(
|
require("https").get(
|
||||||
"https://resurrect.glitch.me/" + process.env.PROJECT_DOMAIN + "",
|
"https://resurrect.glitch.me/" + process.env.PROJECT_DOMAIN + "",
|
||||||
process.exit
|
process.exit
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user