Switch to EJS and bootstrap.
parent
e9aabe6a92
commit
7b7d2bb2ae
|
@ -1,2 +1 @@
|
||||||
node_modules/
|
node_modules/
|
||||||
dist/
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
// Import things
|
||||||
|
const express = require('express');
|
||||||
|
const app = express();
|
||||||
|
const server = require('http').createServer(app);
|
||||||
|
const port = process.env.PORT || 3430;
|
||||||
|
|
||||||
|
// Set the templates folder for the thingy
|
||||||
|
app.set('views', __dirname + '/../Templates');
|
||||||
|
app.set('view engine', 'ejs');
|
||||||
|
|
||||||
|
// Makes it so that the Public folder mounts under /
|
||||||
|
app.use(express.static(__dirname + '/../Public'));
|
||||||
|
|
||||||
|
// Main page
|
||||||
|
app.get('/', function(req, res){
|
||||||
|
res.render('index');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Simple way to expose a function
|
||||||
|
exports = module.exports = rws;
|
||||||
|
|
||||||
|
// rws = RunWebServer
|
||||||
|
function rws() {
|
||||||
|
server.listen(port, () => {
|
||||||
|
console.log('✅ Webserver is running ( %d )', port);
|
||||||
|
});
|
||||||
|
};
|
|
@ -0,0 +1,3 @@
|
||||||
|
#cssloaded {
|
||||||
|
color:deepskyblue;
|
||||||
|
}
|
|
@ -1,77 +0,0 @@
|
||||||
import type { NextFunction, Request, Response } from "express";
|
|
||||||
import type { SessionOptions } from "express-session";
|
|
||||||
import { Liquid } from "liquidjs";
|
|
||||||
import { readFileSync, readdirSync } from "fs";
|
|
||||||
import crypto from "crypto";
|
|
||||||
import express from "express";
|
|
||||||
import expressSession from "express-session";
|
|
||||||
import path from "path";
|
|
||||||
|
|
||||||
const isProduction = process.env.NODE_ENV === "production";
|
|
||||||
const LAYOUTS_DIRECTORY = path.join(__dirname, "layouts");
|
|
||||||
const PARTIALS_DIRECTORY = path.join(__dirname, "partials");
|
|
||||||
const PUBLIC_DIRECTORY = path.join(__dirname, "public");
|
|
||||||
const VIEWS_DIRECTORY = path.join(__dirname, "views");
|
|
||||||
const cookieSecret = crypto.randomBytes(48).toString("hex");
|
|
||||||
|
|
||||||
export function startWebserver() {
|
|
||||||
const app = express();
|
|
||||||
app.disable("x-powered-by");
|
|
||||||
|
|
||||||
app.use((_req, res, next) => {
|
|
||||||
res.header("Permissions-Policy", "interest-cohort=()");
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
const noCache = (_req: Request, res: Response, next: NextFunction) => {
|
|
||||||
res.header("Cache-Control", "no-cache");
|
|
||||||
next();
|
|
||||||
};
|
|
||||||
|
|
||||||
const sessionOptions: SessionOptions = {
|
|
||||||
secret: cookieSecret,
|
|
||||||
name: "Session",
|
|
||||||
resave: false,
|
|
||||||
saveUninitialized: false,
|
|
||||||
unset: "destroy",
|
|
||||||
cookie: {
|
|
||||||
maxAge: 1000 * 60 * 60 * 24 * 7,
|
|
||||||
signed: true,
|
|
||||||
path: "/",
|
|
||||||
httpOnly: true,
|
|
||||||
sameSite: "lax",
|
|
||||||
// If you are getting infinite redirects, set this to "false" if you don't have a HTTPS-only environment setup.
|
|
||||||
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
app.use(expressSession(sessionOptions));
|
|
||||||
app.use(express.urlencoded({ extended: true, limit: "1mb" }));
|
|
||||||
app.use(express.json({ limit: "1mb" }));
|
|
||||||
|
|
||||||
const engine = new Liquid({
|
|
||||||
root: [VIEWS_DIRECTORY, PARTIALS_DIRECTORY, LAYOUTS_DIRECTORY],
|
|
||||||
cache: isProduction,
|
|
||||||
lenientIf: true,
|
|
||||||
jsTruthy: true,
|
|
||||||
extname: ".liquid",
|
|
||||||
});
|
|
||||||
|
|
||||||
app.engine("liquid", engine.express());
|
|
||||||
app.set("views", [VIEWS_DIRECTORY, PARTIALS_DIRECTORY, LAYOUTS_DIRECTORY]);
|
|
||||||
app.set("view engine", "liquid");
|
|
||||||
|
|
||||||
app.use("/public/", express.static(PUBLIC_DIRECTORY));
|
|
||||||
|
|
||||||
// 404
|
|
||||||
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,17 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Hello world!</title>
|
||||||
|
|
||||||
|
<!-- Links -->
|
||||||
|
<link href="style.css" rel="stylesheet" type="text/css">
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1 id="cssloaded">Hello world!</h1>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-u1OknCvxWvY5kfmNBILK2hRnQC3Pr17a+RTT6rIHI7NnikvbZlHgTPOOmMi466C8" crossorigin="anonymous"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,2 @@
|
||||||
|
var rws = require("./Components/webserver.js");
|
||||||
|
rws();
|
File diff suppressed because it is too large
Load Diff
15
package.json
15
package.json
|
@ -1,13 +1,6 @@
|
||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.18.1",
|
"ejs": "^3.1.8",
|
||||||
"express-session": "^1.17.3",
|
"express": "^4.18.1"
|
||||||
"liquidjs": "^9.42.0",
|
}
|
||||||
"typescript": "^4.8.3"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/express": "^4.17.14",
|
|
||||||
"@types/express-session": "^1.17.5",
|
|
||||||
"@types/node": "^18.7.18"
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"allowJs": false,
|
|
||||||
"allowSyntheticDefaultImports": true,
|
|
||||||
"alwaysStrict": true,
|
|
||||||
"baseUrl": "./Source",
|
|
||||||
"checkJs": false,
|
|
||||||
"declaration": false,
|
|
||||||
"emitDecoratorMetadata": true,
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
"importsNotUsedAsValues": "error",
|
|
||||||
"incremental": true,
|
|
||||||
"inlineSources": true,
|
|
||||||
"lib": ["es2020"],
|
|
||||||
"module": "commonjs",
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"noEmit": false,
|
|
||||||
"noEmitOnError": true,
|
|
||||||
"noImplicitAny": true,
|
|
||||||
"noImplicitReturns": false,
|
|
||||||
"noImplicitThis": true,
|
|
||||||
"noUnusedLocals": false,
|
|
||||||
"noUnusedParameters": false,
|
|
||||||
"outDir": "./dist",
|
|
||||||
"pretty": true,
|
|
||||||
"removeComments": true,
|
|
||||||
"resolveJsonModule": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"sourceMap": true,
|
|
||||||
"sourceRoot": "/",
|
|
||||||
"strict": true,
|
|
||||||
"strictBindCallApply": true,
|
|
||||||
"strictNullChecks": false,
|
|
||||||
"suppressImplicitAnyIndexErrors": true,
|
|
||||||
"target": "es2020",
|
|
||||||
"typeRoots": ["./Source/typings"]
|
|
||||||
},
|
|
||||||
"exclude": ["node_modules"],
|
|
||||||
"include": ["Source/**/*"]
|
|
||||||
}
|
|
Loading…
Reference in New Issue