Compare commits
No commits in common. "27d505054730768f19f6c849d9fd12f9b327908a" and "3e999d9d462c377fdc53edcb6ac481a7b9e62841" have entirely different histories.
27d5050547
...
3e999d9d46
21
.prettierrc
21
.prettierrc
|
@ -1,21 +0,0 @@
|
||||||
{
|
|
||||||
"arrowParens": "always",
|
|
||||||
"endOfLine": "lf",
|
|
||||||
"proseWrap": "preserve",
|
|
||||||
"quoteProps": "consistent",
|
|
||||||
"trailingComma": "all",
|
|
||||||
"printWidth": 140,
|
|
||||||
"tabWidth": 2,
|
|
||||||
"semi": true,
|
|
||||||
"singleQuote": false,
|
|
||||||
"useTabs": false,
|
|
||||||
"overrides": [
|
|
||||||
{
|
|
||||||
"files": ["*.liquid"],
|
|
||||||
"options": {
|
|
||||||
"parser": "angular"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,52 +1,21 @@
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import { Liquid } from "liquidjs";
|
import { Liquid } from "liquidjs";
|
||||||
import path from "path";
|
const engine = new Liquid();
|
||||||
|
const app = express();
|
||||||
|
const port = 3430;
|
||||||
|
|
||||||
//import { apiRoutes } from "./routes/api";
|
app.engine('liquid', engine.express());
|
||||||
//import { authRoutes } from "./routes/auth";
|
app.set('views', ['./partials', './views']);
|
||||||
import { indexRoutes } from "./routes/index";
|
app.set('view engine', 'liquid');
|
||||||
|
|
||||||
const isProduction = process.env.NODE_ENV === "production";
|
app.get('/', function (req, res) {
|
||||||
const LAYOUTS_DIRECTORY = path.join(__dirname, "layouts");
|
const todos = ['fork and clone', 'make it better', 'make a pull request']
|
||||||
const PARTIALS_DIRECTORY = path.join(__dirname, "partials");
|
res.render('todolist', {
|
||||||
const PUBLIC_DIRECTORY = path.join(__dirname, "public");
|
todos: todos,
|
||||||
const VIEWS_DIRECTORY = path.join(__dirname, "views");
|
title: 'Welcome to liquidjs!'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
export function startWebserver(config:any) {
|
app.listen(port, () => {
|
||||||
const app = express();
|
console.log('✅ Webserver started on port ', port)
|
||||||
app.disable("x-powered-by");
|
})
|
||||||
|
|
||||||
app.use(express.urlencoded({ extended: true, limit: "1mb" }));
|
|
||||||
app.use(express.json({ limit: "1mb" }));
|
|
||||||
|
|
||||||
// Liquid engine options
|
|
||||||
const engine = new Liquid({
|
|
||||||
root: [VIEWS_DIRECTORY, PARTIALS_DIRECTORY, LAYOUTS_DIRECTORY],
|
|
||||||
cache: isProduction,
|
|
||||||
lenientIf: true,
|
|
||||||
jsTruthy: true,
|
|
||||||
extname: ".liquid",
|
|
||||||
});
|
|
||||||
|
|
||||||
// View engine options
|
|
||||||
app.engine("liquid", engine.express());
|
|
||||||
app.set("views", [VIEWS_DIRECTORY, PARTIALS_DIRECTORY, LAYOUTS_DIRECTORY]);
|
|
||||||
app.set("view engine", "liquid");
|
|
||||||
|
|
||||||
// Uses public folder
|
|
||||||
app.use("/public/", express.static(PUBLIC_DIRECTORY));
|
|
||||||
|
|
||||||
// Routes
|
|
||||||
app.use("/", indexRoutes());
|
|
||||||
|
|
||||||
// 404 handler
|
|
||||||
app.use((req, res) => {
|
|
||||||
if (req.accepts("html")) return res.status(404).render("404", { url: req.url, errorCode: 404 });
|
|
||||||
else if (req.accepts("json")) return res.status(404).send({ error: "404" });
|
|
||||||
else res.status(404).type("txt").send("404");
|
|
||||||
});
|
|
||||||
|
|
||||||
app.listen(3430, "0.0.0.0", () => {
|
|
||||||
console.log(`Webserver running on port 3430`);
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
/**
|
|
||||||
* @file Index routes
|
|
||||||
* @description Routings for the index page and it's redirects
|
|
||||||
* @module webserver/routes/index
|
|
||||||
*/
|
|
||||||
|
|
||||||
import express from "express";
|
|
||||||
import rateLimit from "express-rate-limit";
|
|
||||||
const router = express.Router();
|
|
||||||
|
|
||||||
|
|
||||||
const indexRateLimit = rateLimit({
|
|
||||||
windowMs: 1 * 60 * 1000,
|
|
||||||
max: 50,
|
|
||||||
message: "Too many requests in a short period of time.",
|
|
||||||
});
|
|
||||||
|
|
||||||
export function indexRoutes() {
|
|
||||||
// Index
|
|
||||||
router.get("/", indexRateLimit,async (req,res) => {
|
|
||||||
res.render("index", {
|
|
||||||
//locales: getWebLocale(bot, locale),
|
|
||||||
page: req.url,
|
|
||||||
//user: user,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
|
|
||||||
// Gitea
|
|
||||||
router.get("/gitea/", async (_req, res) => {
|
|
||||||
res.redirect(301, "https://tea.nightly.town/Mangoberry/MangoRecipe");
|
|
||||||
});
|
|
||||||
|
|
||||||
// robots.txt
|
|
||||||
router.get("/robots.txt", async (_req, res) => {
|
|
||||||
res.type("text/plain");
|
|
||||||
res.send("User-agent: *\nCrawl-delay: 5\nDisallow: /public/\nDisallow: /auth/");
|
|
||||||
});
|
|
||||||
|
|
||||||
return router;
|
|
||||||
};
|
|
|
@ -1,12 +0,0 @@
|
||||||
import path from "path";
|
|
||||||
import { startWebserver } from "../Webserver/index";
|
|
||||||
import config from "../../config.json";
|
|
||||||
|
|
||||||
export class MangoRecipe {
|
|
||||||
config: typeof config;
|
|
||||||
// Starts webservers at first boot
|
|
||||||
constructor() {
|
|
||||||
this.config = config;
|
|
||||||
startWebserver(this);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
/**
|
|
||||||
* @file Index
|
|
||||||
* @description Creates an instance of Hibiki
|
|
||||||
* @license AGPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { MangoRecipe } from "./classes/Main";
|
|
||||||
import config from "../config.json";
|
|
||||||
|
|
||||||
new MangoRecipe();
|
|
|
@ -10,7 +10,6 @@
|
||||||
"license": "GPL-2.0-or-later",
|
"license": "GPL-2.0-or-later",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"express-rate-limit": "^6.6.0",
|
|
||||||
"express-session": "^1.17.3",
|
"express-session": "^1.17.3",
|
||||||
"liquidjs": "^9.42.0",
|
"liquidjs": "^9.42.0",
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
|
@ -1454,17 +1453,6 @@
|
||||||
"node": ">= 0.10.0"
|
"node": ">= 0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/express-rate-limit": {
|
|
||||||
"version": "6.6.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-6.6.0.tgz",
|
|
||||||
"integrity": "sha512-HFN2+4ZGdkQOS8Qli4z6knmJFnw6lZed67o6b7RGplWeb1Z0s8VXaj3dUgPIdm9hrhZXTRpCTHXA0/2Eqex0vA==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 12.9.0"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"express": "^4 || ^5"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/express-session": {
|
"node_modules/express-session": {
|
||||||
"version": "1.17.3",
|
"version": "1.17.3",
|
||||||
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.3.tgz",
|
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.3.tgz",
|
||||||
|
@ -4599,12 +4587,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"express-rate-limit": {
|
|
||||||
"version": "6.6.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-6.6.0.tgz",
|
|
||||||
"integrity": "sha512-HFN2+4ZGdkQOS8Qli4z6knmJFnw6lZed67o6b7RGplWeb1Z0s8VXaj3dUgPIdm9hrhZXTRpCTHXA0/2Eqex0vA==",
|
|
||||||
"requires": {}
|
|
||||||
},
|
|
||||||
"express-session": {
|
"express-session": {
|
||||||
"version": "1.17.3",
|
"version": "1.17.3",
|
||||||
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.3.tgz",
|
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.3.tgz",
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"express-rate-limit": "^6.6.0",
|
|
||||||
"express-session": "^1.17.3",
|
"express-session": "^1.17.3",
|
||||||
"liquidjs": "^9.42.0",
|
"liquidjs": "^9.42.0",
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
|
|
Loading…
Reference in New Issue