mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-07-09 07:07:50 +02:00
move PORT to the config
This commit is contained in:
@@ -5,7 +5,8 @@ const config = {
|
|||||||
MAX_FILE_SIZE: 10 * 1024 * 1024, // in b
|
MAX_FILE_SIZE: 10 * 1024 * 1024, // in b
|
||||||
MAX_REPO_SIZE: 8 * 1024, // in kb
|
MAX_REPO_SIZE: 8 * 1024, // in kb
|
||||||
AUTH_CALLBACK: "http://localhost:5000/github/auth",
|
AUTH_CALLBACK: "http://localhost:5000/github/auth",
|
||||||
ANONYMIZATION_MASK: "XXXX"
|
ANONYMIZATION_MASK: "XXXX",
|
||||||
|
PORT: 5000,
|
||||||
};
|
};
|
||||||
for (let conf in process.env) {
|
for (let conf in process.env) {
|
||||||
if (config[conf] !== undefined) {
|
if (config[conf] !== undefined) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ const express = require("express");
|
|||||||
const compression = require("compression");
|
const compression = require("compression");
|
||||||
const bodyParser = require("body-parser");
|
const bodyParser = require("body-parser");
|
||||||
|
|
||||||
|
const config = require("./config");
|
||||||
const rediscli = redis.createClient({
|
const rediscli = redis.createClient({
|
||||||
host: "redis",
|
host: "redis",
|
||||||
ttl: 260,
|
ttl: 260,
|
||||||
@@ -18,8 +19,6 @@ const connection = require("./routes/connection");
|
|||||||
const db = require("./utils/database");
|
const db = require("./utils/database");
|
||||||
const fileUtils = require("./utils/file");
|
const fileUtils = require("./utils/file");
|
||||||
|
|
||||||
const PORT = process.env.PORT || 5000;
|
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
app.use(compression());
|
app.use(compression());
|
||||||
@@ -75,10 +74,18 @@ app.get("/api/stat", async (_, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function indexResponse(req, res) {
|
function indexResponse(req, res) {
|
||||||
if (req.params.repoId && req.headers["accept"] && req.headers["accept"].indexOf("text/html") == -1) {
|
if (
|
||||||
|
req.params.repoId &&
|
||||||
|
req.headers["accept"] &&
|
||||||
|
req.headers["accept"].indexOf("text/html") == -1
|
||||||
|
) {
|
||||||
const repoId = req.path.split("/")[2];
|
const repoId = req.path.split("/")[2];
|
||||||
// if it is not an html request, it assumes that the browser try to load a different type of resource
|
// if it is not an html request, it assumes that the browser try to load a different type of resource
|
||||||
return res.redirect(`/api/repo/${repoId}/file/${req.path.substring(req.path.indexOf(repoId) + repoId.length + 1)}`);
|
return res.redirect(
|
||||||
|
`/api/repo/${repoId}/file/${req.path.substring(
|
||||||
|
req.path.indexOf(repoId) + repoId.length + 1
|
||||||
|
)}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
res.sendFile(path.resolve(__dirname, "public", "index.html"));
|
res.sendFile(path.resolve(__dirname, "public", "index.html"));
|
||||||
}
|
}
|
||||||
@@ -95,8 +102,9 @@ app.use(express.static(__dirname + "/public"));
|
|||||||
app.get("*", indexResponse);
|
app.get("*", indexResponse);
|
||||||
|
|
||||||
db.connect().then((_) => {
|
db.connect().then((_) => {
|
||||||
app.listen(PORT, () => {
|
app.listen(config.PORT, () => {
|
||||||
console.log("Database connected and Server started on port: " + PORT);
|
console.log(
|
||||||
|
"Database connected and Server started on port: " + config.PORT
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user