mirror of
https://github.com/Sebclem/hassio-nextcloud-backup.git
synced 2024-09-12 00:39:06 +02:00
Rework env selection
This commit is contained in:
parent
a22962902d
commit
bd0fbe81c2
@ -1,8 +1,7 @@
|
|||||||
import cookieParser from "cookie-parser";
|
import cookieParser from "cookie-parser";
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import errorHandler from "errorhandler";
|
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import createError from "http-errors";
|
|
||||||
import morgan from "morgan";
|
import morgan from "morgan";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
@ -20,10 +19,11 @@ app.use(
|
|||||||
);
|
);
|
||||||
|
|
||||||
app.set("port", process.env.PORT || 3000);
|
app.set("port", process.env.PORT || 3000);
|
||||||
|
if (process.env.ACCESS_LOG == "true") {
|
||||||
// app.use(
|
app.use(
|
||||||
// morgan("dev", { stream: { write: (message) => logger.debug(message) } })
|
morgan("dev", { stream: { write: (message) => logger.debug(message) } })
|
||||||
// );
|
);
|
||||||
|
}
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(express.urlencoded({ extended: false }));
|
app.use(express.urlencoded({ extended: false }));
|
||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
@ -36,15 +36,4 @@ app.use("/v2/api/", apiV2Router);
|
|||||||
----------------------------------------------------------
|
----------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// error handler
|
|
||||||
if (app.get("env") == "development") {
|
|
||||||
// catch 404 and forward to error handler
|
|
||||||
app.use((req, res, next) => {
|
|
||||||
next(createError(404));
|
|
||||||
});
|
|
||||||
|
|
||||||
// only use in development
|
|
||||||
app.use(errorHandler());
|
|
||||||
}
|
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
@ -1,16 +1,21 @@
|
|||||||
import errorHandler from "errorhandler";
|
|
||||||
import "./env.js";
|
import "./env.js";
|
||||||
|
|
||||||
|
import errorHandler from "errorhandler";
|
||||||
|
import figlet from "figlet";
|
||||||
|
import createError from "http-errors";
|
||||||
|
import kleur from "kleur";
|
||||||
import app from "./app.js";
|
import app from "./app.js";
|
||||||
import logger from "./config/winston.js";
|
import logger from "./config/winston.js";
|
||||||
import postInit from "./postInit.js";
|
import postInit from "./postInit.js";
|
||||||
import figlet from "figlet";
|
|
||||||
import kleur from "kleur";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error Handler. Provides full stack
|
* Error Handler. Provides full stack
|
||||||
*/
|
*/
|
||||||
if (process.env.NODE_ENV === "development") {
|
if (process.env.NODE_ENV === "development") {
|
||||||
app.use(errorHandler());
|
app.use(errorHandler());
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
next(createError(404));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,7 +27,7 @@ const server = app.listen(app.get("port"), () => {
|
|||||||
`App is running at ` +
|
`App is running at ` +
|
||||||
kleur.green().bold(`http://localhost:${app.get("port")}`) +
|
kleur.green().bold(`http://localhost:${app.get("port")}`) +
|
||||||
" in " +
|
" in " +
|
||||||
kleur.green().bold(app.get("env") as string) +
|
kleur.green().bold(process.env.NODE_ENV || "production") +
|
||||||
" mode"
|
" mode"
|
||||||
);
|
);
|
||||||
logger.info(kleur.red().bold("Press CTRL-C to stop"));
|
logger.info(kleur.red().bold("Press CTRL-C to stop"));
|
||||||
|
Loading…
Reference in New Issue
Block a user