hassio-nextcloud-backup/nextcloud_backup/backend/src/app.ts
2024-07-12 16:44:04 +02:00

40 lines
980 B
TypeScript

import cookieParser from "cookie-parser";
import cors from "cors";
import express from "express";
import morgan from "morgan";
import path from "path";
import { fileURLToPath } from "url";
import logger from "./config/winston.js";
import apiV2Router from "./routes/apiV2.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
app.use(
cors({
origin: true,
})
);
app.set("port", process.env.PORT || 3000);
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());
app.use(express.static(path.join(__dirname, "public")));
app.use("/v2/api/", apiV2Router);
/*
-----------------------------------------------------------
Error handler
----------------------------------------------------------
*/
export default app;