
// Load WebServer
import express from "express";
import { router } from "express-file-routing"

// Load Templating Engine
import Nunjucks from "nunjucks";

// Initialize WebServer
const app = express();
const port = 3000;

// Middleware, um CORS zu aktivieren
app.use((req, res, next) => {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
    res.header("Access-Control-Allow-Headers", "Content-Type, Authorization");
    next();
});

// Configure Templating Engine
Nunjucks.configure('./', {
    autoescape: false,
    express: app,
    noCache: true
});

// Mount Middlewares to WebServer
app.use(express.json());
app.use(express.urlencoded());
app.use(express.static('./assets/'))
app.use("/", await router());

// Server starten
app.listen(port, () => {
    console.log(`Server is listening on port ${port}`);
});