add /static dir for js files owo

This commit is contained in:
Ashley 2023-04-12 20:41:37 +00:00
parent 52cebeb965
commit b0591974c8

View file

@ -24,7 +24,7 @@ module.exports = function (app, config, renderTemplate) {
var html_location = "./css/";
app.get("/privacy", function (req, res) {
if ( req.hostname == "poketube.fun" ) {
if (req.hostname == "poketube.fun") {
renderTemplate(res, req, "priv.ejs", {
isMobile: req.useragent.isMobile,
});
@ -64,13 +64,13 @@ module.exports = function (app, config, renderTemplate) {
});
});
const path = require("path");
const fs = require("fs");
const CleanCSS = require("clean-css");
const path = require("path");
const fs = require("fs");
const CleanCSS = require("clean-css");
const cssDir = "./css/";
const cssDir = "./css/";
app.get("/css/:id", (req, res) => {
app.get("/css/:id", (req, res) => {
const filePath = path.join(cssDir, req.params.id);
if (!fs.existsSync(filePath)) {
res.status(404).send("File not found");
@ -88,7 +88,17 @@ app.get("/css/:id", (req, res) => {
// Serve the original file
res.sendFile(req.params.id, { root: html_location });
}
});
if (req.params.id.endsWith(".js")) {
res.redirect("/static/" + req.params.id);
}
});
app.get("/static/:id", (req, res) => {
if (req.params.id.endsWith(".css")) {
res.redirect("/css/" + req.params.id);
}
res.sendFile(req.params.id, { root: html_location });
});
};