This repository has been archived on 2024-01-23. You can view files and clone it, but cannot push or open issues/pull-requests.
API/index.ts

66 lines
1.6 KiB
TypeScript

import express, { Express } from "express";
import dotenv from "dotenv";
import bodyParser = require("body-parser");
dotenv.config();
import swaggerJsDoc from "swagger-jsdoc";
const app: Express = express();
const port = process.env.PORT || 3000;
import { initDatabase } from "./src/mongodb/mongodb";
import swaggerUI from "swagger-ui-express";
import adminRoutes from "./src/routes/adminRoutes";
import userRoutes from "./src/routes/userRoutes";
import eventRoutes from "./src/routes/eventRoutes";
const options = {
definition: {
openapi: "3.0.0",
info: {
title: "PartyApp API",
version: "1.0.0",
//description: "PartyApp API",
//termsOfService: "http://example.com/terms/",
/*contact: {
name: "API Support",
url: "http://www.exmaple.com/support",
email: "support@example.com",
},*/
},
servers: [
{
url: "http://localhost:3000/api/v1",
//description: "PartyApp API Documentation",
},
],
},
apis: ["./src/routes/*.ts"],
};
app.use(bodyParser.json());
app.use("/api/v1/user", userRoutes);
app.use("/api/v1/admin", adminRoutes);
app.use("/api/v1/events", eventRoutes);
const specs = swaggerJsDoc(options);
app.use("/api-docs", swaggerUI.serve, swaggerUI.setup(specs));
app.use((req, res, next) => {
res.status(404).send("not found");
});
app.use((err: any, req: any, res: any, next: any) => {
console.log("req err", err.stack);
res.status(500).send({ err: "invalid request" });
});
initDatabase();
app.listen(port, () => {
console.log(`⚡️[server]: Server is running at http://localhost:${port}`);
});