
// Load WebServer
import {
    default as express
} from "express";

import {
    router
} from "express-file-routing"

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

// Initialize WebServer
const expressApp = express();
const expressPort = 3000;

// Middleware, um CORS zu aktivieren
expressApp.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: expressApp,
    noCache: true
});

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

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