2020-06-22 09:54:01 +00:00
|
|
|
process.env.NODE_ENV = process.env.NODE_ENV || "development";
|
|
|
|
|
2022-02-09 13:13:53 +00:00
|
|
|
if (!process.env.PORTAL_DOMAIN) {
|
|
|
|
throw new Error("You need to provide PORTAL_DOMAIN environment variable");
|
|
|
|
}
|
|
|
|
|
2022-01-13 20:41:56 +00:00
|
|
|
if (process.env.ACCOUNTS_ENABLED === "true") {
|
2022-01-21 16:43:30 +00:00
|
|
|
if (["authenticated", "subscription"].includes(process.env.ACCOUNTS_LIMIT_ACCESS)) {
|
2022-01-13 20:41:56 +00:00
|
|
|
if (!process.env.ACCOUNTS_TEST_USER_EMAIL) {
|
|
|
|
throw new Error("ACCOUNTS_TEST_USER_EMAIL cannot be empty");
|
|
|
|
}
|
|
|
|
if (!process.env.ACCOUNTS_TEST_USER_PASSWORD) {
|
|
|
|
throw new Error("ACCOUNTS_TEST_USER_PASSWORD cannot be empty");
|
|
|
|
}
|
|
|
|
}
|
2020-06-22 09:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const express = require("express");
|
2020-09-18 11:40:14 +00:00
|
|
|
const db = require("./db");
|
2020-06-22 09:54:01 +00:00
|
|
|
|
2020-07-27 17:03:05 +00:00
|
|
|
const host = process.env.HOSTNAME || "0.0.0.0";
|
2020-07-30 10:00:58 +00:00
|
|
|
const port = Number(process.env.PORT) || 3100;
|
2020-06-22 09:54:01 +00:00
|
|
|
|
|
|
|
const server = express();
|
|
|
|
|
2021-04-16 10:10:16 +00:00
|
|
|
server.use(express.urlencoded({ extended: false }));
|
|
|
|
server.use(express.json());
|
2020-09-18 11:40:14 +00:00
|
|
|
server.use((req, res, next) => {
|
|
|
|
db.read();
|
|
|
|
next();
|
2020-09-18 14:59:46 +00:00
|
|
|
});
|
2020-06-22 09:54:01 +00:00
|
|
|
|
2020-09-09 12:25:00 +00:00
|
|
|
server.get("/health-check", require("./api/index"));
|
2020-09-10 10:15:54 +00:00
|
|
|
server.get("/health-check/critical", require("./api/critical"));
|
2021-04-29 11:43:40 +00:00
|
|
|
server.get("/health-check/extended", require("./api/extended"));
|
2020-09-09 12:53:05 +00:00
|
|
|
server.get("/health-check/disabled", require("./api/disabled"));
|
2020-06-22 09:54:01 +00:00
|
|
|
|
|
|
|
server.listen(port, host, (error) => {
|
|
|
|
if (error) throw error;
|
|
|
|
|
|
|
|
console.info(`Server listening at http://${host}:${port} (NODE_ENV: ${process.env.NODE_ENV})`);
|
2022-02-08 11:22:49 +00:00
|
|
|
|
|
|
|
const { ipRegex } = require("./utils");
|
|
|
|
|
|
|
|
if (ipRegex.test(process.env.serverip)) {
|
|
|
|
console.info(`Server public ip: ${process.env.serverip}`);
|
|
|
|
}
|
2020-06-22 09:54:01 +00:00
|
|
|
});
|