mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-22 21:57:49 +01:00
more gooda formating and try catch blocks :3
This commit is contained in:
parent
e4c9102efe
commit
5ec7953289
1 changed files with 22 additions and 28 deletions
40
server.js
40
server.js
|
@ -33,14 +33,7 @@
|
||||||
const { sinit } = require("./src/libpoketube/init/superinit.js");
|
const { sinit } = require("./src/libpoketube/init/superinit.js");
|
||||||
const u = await media_proxy();
|
const u = await media_proxy();
|
||||||
initlog("Loading...");
|
initlog("Loading...");
|
||||||
initlog(
|
initlog("[Welcome] Welcome To PokeTube :3 " +"Running " +`Node ${process.version} - V8 v${process.versions.v8} - ${process.platform.replace("linux", "GNU/Linux")} ${process.arch} Server - libpt ${version}`
|
||||||
"[Welcome] Welcome To PokeTube :3 " +
|
|
||||||
"Running " +
|
|
||||||
`Node ${process.version} - V8 v${
|
|
||||||
process.versions.v8
|
|
||||||
} - ${process.platform.replace("linux", "GNU/Linux")} ${
|
|
||||||
process.arch
|
|
||||||
} Server - libpt ${version}`
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
@ -70,10 +63,7 @@
|
||||||
app.enable("trust proxy");
|
app.enable("trust proxy");
|
||||||
|
|
||||||
const renderTemplate = async (res, req, template, data = {}) => {
|
const renderTemplate = async (res, req, template, data = {}) => {
|
||||||
res.render(
|
res.render(modules.path.resolve(`${templateDir}${modules.path.sep}${template}`),Object.assign(data));
|
||||||
modules.path.resolve(`${templateDir}${modules.path.sep}${template}`),
|
|
||||||
Object.assign(data)
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const random_words = [
|
const random_words = [
|
||||||
|
@ -102,6 +92,7 @@ this is our config file,you can change stuff here
|
||||||
t_url: "https://t.poketube.fun/", // def matomo url
|
t_url: "https://t.poketube.fun/", // def matomo url
|
||||||
};
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
app.use(function (req, res, next) {
|
app.use(function (req, res, next) {
|
||||||
res.header("Access-Control-Allow-Origin", "*");
|
res.header("Access-Control-Allow-Origin", "*");
|
||||||
if (req.secure) {
|
if (req.secure) {
|
||||||
|
@ -117,8 +108,10 @@ this is our config file,you can change stuff here
|
||||||
|
|
||||||
app.use(function (request, response, next) {
|
app.use(function (request, response, next) {
|
||||||
if (config.enablealwayshttps && !request.secure) {
|
if (config.enablealwayshttps && !request.secure) {
|
||||||
|
if (!/^https:/i.test(request.headers["x-forwarded-proto"] || request.protocol)) {
|
||||||
return response.redirect("https://" + request.headers.host + request.url);
|
return response.redirect("https://" + request.headers.host + request.url);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
@ -126,33 +119,34 @@ this is our config file,you can change stuff here
|
||||||
app.use(function (req, res, next) {
|
app.use(function (req, res, next) {
|
||||||
res.header("X-PokeTube-Youtube-Client-Name", "1");
|
res.header("X-PokeTube-Youtube-Client-Name", "1");
|
||||||
res.header("X-PokeTube-Youtube-Client-Version", "2.20210721.00.00");
|
res.header("X-PokeTube-Youtube-Client-Version", "2.20210721.00.00");
|
||||||
res.header("X-PokeTube-Speeder", "6 seconds no cache, 780ms w/cache")
|
res.header("X-PokeTube-Speeder", "6 seconds no cache, 780ms w/cache");
|
||||||
if (req.url.match(/^\/(css|js|img|font)\/.+/)) {
|
if (req.url.match(/^\/(css|js|img|font)\/.+/)) {
|
||||||
res.setHeader(
|
res.setHeader("Cache-Control","public, max-age=" + config.cacher_max_age); // cache header
|
||||||
"Cache-Control",
|
|
||||||
"public, max-age=" + config.cacher_max_age
|
|
||||||
); // cache header
|
|
||||||
res.setHeader("poketube-cacher", "STATIC_FILES");
|
res.setHeader("poketube-cacher", "STATIC_FILES");
|
||||||
}
|
}
|
||||||
|
|
||||||
const a = 890;
|
const a = 890;
|
||||||
if (!req.url.match(/^\/(css|js|img|font)\/.+/)) {
|
if (!req.url.match(/^\/(css|js|img|font)\/.+/)) {
|
||||||
res.setHeader(
|
res.setHeader("Cache-Control", "public, max-age=" + a); // cache header
|
||||||
"Cache-Control",
|
|
||||||
"public, max-age=" + a
|
|
||||||
); // cache header
|
|
||||||
res.setHeader("poketube-cacher", "PAGE");
|
res.setHeader("poketube-cacher", "PAGE");
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
initlog("[OK] Load headers")
|
initlog("[OK] Load headers");
|
||||||
|
} catch {
|
||||||
|
initlog("[FAILED] load headers")
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
app.get("/robots.txt", (req, res) => {
|
app.get("/robots.txt", (req, res) => {
|
||||||
res.sendFile(__dirname + "/robots.txt");
|
res.sendFile(__dirname + "/robots.txt");
|
||||||
});
|
});
|
||||||
|
|
||||||
initlog("[OK] Load robots.txt")
|
initlog("[OK] Load robots.txt");
|
||||||
|
} catch {
|
||||||
|
initlog("[FAILED] load robots.txt")
|
||||||
|
}
|
||||||
|
|
||||||
sinit(app, config, renderTemplate);
|
sinit(app, config, renderTemplate);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue