Reddirect 404erro only on dev

This commit is contained in:
SebClem 2024-07-12 14:31:24 +02:00
parent bd444ad8d6
commit f6db3499a4
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50

View File

@ -21,9 +21,9 @@ app.use(
app.set("port", process.env.PORT || 3000); app.set("port", process.env.PORT || 3000);
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());
@ -35,13 +35,14 @@ app.use("/v2/api/", apiV2Router);
Error handler Error handler
---------------------------------------------------------- ----------------------------------------------------------
*/ */
// error handler
if (app.get("env") == "development") {
// catch 404 and forward to error handler // catch 404 and forward to error handler
app.use((req, res, next) => { app.use((req, res, next) => {
next(createError(404)); next(createError(404));
}); });
// error handler
if (process.env.NODE_ENV === "development") {
// only use in development // only use in development
app.use(errorHandler()); app.use(errorHandler());
} }