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

40 lines
980 B
TypeScript
Raw Normal View History

2022-09-27 23:38:40 +02:00
import cookieParser from "cookie-parser";
2024-07-11 15:47:27 +02:00
import cors from "cors";
import express from "express";
2024-07-12 16:44:04 +02:00
2022-09-27 23:38:40 +02:00
import morgan from "morgan";
import path from "path";
import { fileURLToPath } from "url";
2022-09-27 23:38:40 +02:00
import logger from "./config/winston.js";
import apiV2Router from "./routes/apiV2.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
2019-12-19 15:08:47 +01:00
const app = express();
2024-07-11 15:47:27 +02:00
app.use(
cors({
origin: true,
})
);
2022-09-27 23:38:40 +02:00
app.set("port", process.env.PORT || 3000);
2024-07-12 16:44:04 +02:00
if (process.env.ACCESS_LOG == "true") {
app.use(
morgan("dev", { stream: { write: (message) => logger.debug(message) } })
);
}
2019-12-19 15:08:47 +01:00
app.use(express.json());
2020-11-09 12:42:26 +01:00
app.use(express.urlencoded({ extended: false }));
2019-12-19 15:08:47 +01:00
app.use(cookieParser());
2020-11-09 12:42:26 +01:00
app.use(express.static(path.join(__dirname, "public")));
2022-09-27 23:38:40 +02:00
app.use("/v2/api/", apiV2Router);
/*
-----------------------------------------------------------
Error handler
----------------------------------------------------------
*/
2019-12-19 15:08:47 +01:00
export default app;