Files
Hackathon_2025/backend/src/index.js
2025-09-11 19:00:11 +02:00

43 lines
1.2 KiB
JavaScript

import fs from 'fs';
import swaggerJsdoc from "swagger-jsdoc";
import swaggerUi from "swagger-ui-express";
import https from 'https';
import express from 'express';
import cors from 'cors';
import path from 'path';
import apiRouter from './api.js';
import { initDB } from './db.js';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.join(path.dirname(__filename), ".."); // going back a dir cuz code is in src/
const app = express();
const specs = swaggerJsdoc({
definition: {
openapi: "3.0.0",
info: {
title: "Analogue Game Assistent API",
version: "1.0.0",
}
},
apis: ["./src/api.js"],
});
initDB();
app.use(cors());
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use(express.static(path.join(__dirname, "public"), {
dotfiles: "ignore"
}));
app.use("/api/docs", swaggerUi.serve, swaggerUi.setup(specs));
app.use("/api", apiRouter);
const server = https.createServer({
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.cert')
}, app).listen(5555, () => {
console.log(`Server running on http://localhost:${server.address().port}`);
});