mirror of
https://github.com/zumbiepig/MineXLauncher.git
synced 2025-06-08 09:24:48 +00:00
.
This commit is contained in:
parent
93174129e1
commit
a3badc8ca1
38
app.js
38
app.js
@ -1,38 +0,0 @@
|
|||||||
import createError from "http-errors";
|
|
||||||
import express, { json, urlencoded, static as serveStatic } from "express";
|
|
||||||
import { join } from "path";
|
|
||||||
import cookieParser from "cookie-parser";
|
|
||||||
import logger from "morgan";
|
|
||||||
|
|
||||||
import indexRouter from "./routes/index.js";
|
|
||||||
import usersRouter from "./routes/users.js";
|
|
||||||
|
|
||||||
const __dirname = import.meta.dirname;
|
|
||||||
|
|
||||||
const app = express();
|
|
||||||
|
|
||||||
app.set("views", join(__dirname, "views"));
|
|
||||||
app.set("view engine", "pug");
|
|
||||||
|
|
||||||
app.use(logger("dev"));
|
|
||||||
app.use(json());
|
|
||||||
app.use(urlencoded({ extended: false }));
|
|
||||||
app.use(cookieParser());
|
|
||||||
app.use(serveStatic(join(__dirname, "public")));
|
|
||||||
|
|
||||||
app.use("/", indexRouter);
|
|
||||||
app.use("/users", usersRouter);
|
|
||||||
|
|
||||||
app.use(function (req, res, next) {
|
|
||||||
next(createError(404));
|
|
||||||
});
|
|
||||||
|
|
||||||
app.use(function (err, req, res, next) {
|
|
||||||
res.locals.message = err.message;
|
|
||||||
res.locals.error = req.app.get("env") === "development" ? err : {};
|
|
||||||
|
|
||||||
res.status(err.status || 500);
|
|
||||||
res.render("error");
|
|
||||||
});
|
|
||||||
|
|
||||||
export default app;
|
|
@ -2,9 +2,9 @@
|
|||||||
"name": "minexlauncher",
|
"name": "minexlauncher",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./bin/www",
|
"main": "./server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node ./bin/www",
|
"start": "node ./server.js",
|
||||||
"build": "npm run build:clean && npm run build:compile && npm run build:obfuscate",
|
"build": "npm run build:clean && npm run build:compile && npm run build:obfuscate",
|
||||||
"build:clean": "rimraf ./public/resources/scripts",
|
"build:clean": "rimraf ./public/resources/scripts",
|
||||||
"build:compile": "tsc",
|
"build:compile": "tsc",
|
||||||
|
@ -1,8 +1,40 @@
|
|||||||
#!/usr/bin/env node
|
import createError from "http-errors";
|
||||||
|
import express, { json, urlencoded, static as serveStatic } from "express";
|
||||||
import app from "../app.js";
|
import { join } from "path";
|
||||||
|
import cookieParser from "cookie-parser";
|
||||||
|
import logger from "morgan";
|
||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
import { createServer } from "http";
|
import { createServer } from "http";
|
||||||
|
import indexRouter from "./routes/index.js";
|
||||||
|
import usersRouter from "./routes/users.js";
|
||||||
|
|
||||||
|
const __dirname = import.meta.dirname;
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
app.set("views", join(__dirname, "views"));
|
||||||
|
app.set("view engine", "pug");
|
||||||
|
|
||||||
|
app.use(logger("dev"));
|
||||||
|
app.use(json());
|
||||||
|
app.use(urlencoded({ extended: false }));
|
||||||
|
app.use(cookieParser());
|
||||||
|
app.use(serveStatic(join(__dirname, "public")));
|
||||||
|
|
||||||
|
app.use("/", indexRouter);
|
||||||
|
app.use("/users", usersRouter);
|
||||||
|
|
||||||
|
app.use(function (req, res, next) {
|
||||||
|
next(createError(404));
|
||||||
|
});
|
||||||
|
|
||||||
|
app.use(function (err, req, res, next) {
|
||||||
|
res.locals.message = err.message;
|
||||||
|
res.locals.error = req.app.get("env") === "development" ? err : {};
|
||||||
|
|
||||||
|
res.status(err.status || 500);
|
||||||
|
res.render("error");
|
||||||
|
});
|
||||||
|
|
||||||
const debugLogger = debug("minexlauncher:server");
|
const debugLogger = debug("minexlauncher:server");
|
||||||
|
|
||||||
@ -17,25 +49,20 @@ server.on("listening", onListening);
|
|||||||
|
|
||||||
function normalizePort(val) {
|
function normalizePort(val) {
|
||||||
const port = parseInt(val, 10);
|
const port = parseInt(val, 10);
|
||||||
|
|
||||||
if (isNaN(port)) {
|
if (isNaN(port)) {
|
||||||
return val;
|
return val;
|
||||||
}
|
} else if (port >= 0) {
|
||||||
|
|
||||||
if (port >= 0) {
|
|
||||||
return port;
|
return port;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onError(error) {
|
function onError(error) {
|
||||||
if (error.syscall !== "listen") {
|
if (error.syscall !== "listen") {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bind = typeof port === "string" ? "Pipe " + port : "Port " + port;
|
const bind = typeof port === "string" ? "Pipe " + port : "Port " + port;
|
||||||
|
|
||||||
switch (error.code) {
|
switch (error.code) {
|
||||||
case "EACCES":
|
case "EACCES":
|
||||||
console.error(bind + " requires elevated privileges");
|
console.error(bind + " requires elevated privileges");
|
Loading…
x
Reference in New Issue
Block a user