hassio-nextcloud-backup/nextcloud_backup/backend/src/server.ts

38 lines
909 B
TypeScript
Raw Normal View History

2022-09-27 23:38:40 +02:00
import "./env.js";
2024-07-12 16:44:04 +02:00
import errorHandler from "errorhandler";
import figlet from "figlet";
import createError from "http-errors";
import kleur from "kleur";
import app from "./app.js";
2022-09-27 23:38:40 +02:00
import logger from "./config/winston.js";
import postInit from "./postInit.js";
/**
* Error Handler. Provides full stack
*/
if (process.env.NODE_ENV === "development") {
2024-07-11 15:47:27 +02:00
app.use(errorHandler());
2024-07-12 16:44:04 +02:00
app.use((req, res, next) => {
next(createError(404));
});
}
/**
* Start Express server.
*/
const server = app.listen(app.get("port"), () => {
2024-07-11 15:47:27 +02:00
console.log(kleur.yellow().bold(figlet.textSync("NC Backup")));
logger.info(
`App is running at ` +
kleur.green().bold(`http://localhost:${app.get("port")}`) +
" in " +
2024-07-12 16:44:04 +02:00
kleur.green().bold(process.env.NODE_ENV || "production") +
2024-07-11 15:47:27 +02:00
" mode"
);
logger.info(kleur.red().bold("Press CTRL-C to stop"));
postInit();
});
2024-07-11 15:47:27 +02:00
export default server;