mirror of
https://github.com/Sebclem/hassio-nextcloud-backup.git
synced 2024-11-05 00:52:59 +01:00
Rework env selection
This commit is contained in:
parent
8f0b6889f7
commit
8510115686
@ -1,8 +1,7 @@
|
||||
import cookieParser from "cookie-parser";
|
||||
import cors from "cors";
|
||||
import errorHandler from "errorhandler";
|
||||
import express from "express";
|
||||
import createError from "http-errors";
|
||||
|
||||
import morgan from "morgan";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
@ -20,10 +19,11 @@ app.use(
|
||||
);
|
||||
|
||||
app.set("port", process.env.PORT || 3000);
|
||||
|
||||
// app.use(
|
||||
// morgan("dev", { stream: { write: (message) => logger.debug(message) } })
|
||||
// );
|
||||
if (process.env.ACCESS_LOG == "true") {
|
||||
app.use(
|
||||
morgan("dev", { stream: { write: (message) => logger.debug(message) } })
|
||||
);
|
||||
}
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: false }));
|
||||
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;
|
||||
|
@ -1,16 +1,21 @@
|
||||
import errorHandler from "errorhandler";
|
||||
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 logger from "./config/winston.js";
|
||||
import postInit from "./postInit.js";
|
||||
import figlet from "figlet";
|
||||
import kleur from "kleur";
|
||||
|
||||
/**
|
||||
* Error Handler. Provides full stack
|
||||
*/
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
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 ` +
|
||||
kleur.green().bold(`http://localhost:${app.get("port")}`) +
|
||||
" in " +
|
||||
kleur.green().bold(app.get("env") as string) +
|
||||
kleur.green().bold(process.env.NODE_ENV || "production") +
|
||||
" mode"
|
||||
);
|
||||
logger.info(kleur.red().bold("Press CTRL-C to stop"));
|
||||
|
Loading…
Reference in New Issue
Block a user