Compare commits
2 Commits
3e999d9d46
...
27d5050547
Author | SHA1 | Date |
---|---|---|
nightly | 27d5050547 | |
nightly | b475b261db |
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"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,21 +1,52 @@
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import { Liquid } from "liquidjs";
|
import { Liquid } from "liquidjs";
|
||||||
const engine = new Liquid();
|
import path from "path";
|
||||||
const app = express();
|
|
||||||
const port = 3430;
|
|
||||||
|
|
||||||
app.engine('liquid', engine.express());
|
//import { apiRoutes } from "./routes/api";
|
||||||
app.set('views', ['./partials', './views']);
|
//import { authRoutes } from "./routes/auth";
|
||||||
app.set('view engine', 'liquid');
|
import { indexRoutes } from "./routes/index";
|
||||||
|
|
||||||
app.get('/', function (req, res) {
|
const isProduction = process.env.NODE_ENV === "production";
|
||||||
const todos = ['fork and clone', 'make it better', 'make a pull request']
|
const LAYOUTS_DIRECTORY = path.join(__dirname, "layouts");
|
||||||
res.render('todolist', {
|
const PARTIALS_DIRECTORY = path.join(__dirname, "partials");
|
||||||
todos: todos,
|
const PUBLIC_DIRECTORY = path.join(__dirname, "public");
|
||||||
title: 'Welcome to liquidjs!'
|
const VIEWS_DIRECTORY = path.join(__dirname, "views");
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
app.listen(port, () => {
|
export function startWebserver(config:any) {
|
||||||
console.log('✅ Webserver started on port ', port)
|
const app = express();
|
||||||
})
|
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`);
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
/**
|
||||||
|
* @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;
|
||||||
|
};
|
|
@ -0,0 +1,12 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
/**
|
||||||
|
* @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,6 +10,7 @@
|
||||||
"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",
|
||||||
|
@ -1453,6 +1454,17 @@
|
||||||
"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",
|
||||||
|
@ -4587,6 +4599,12 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"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,6 +27,7 @@
|
||||||
},
|
},
|
||||||
"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