add athorization to all calls except auth

This commit is contained in:
Anika Raemer 2025-09-24 21:24:20 +02:00
parent 8fb48f7243
commit 5dd79374c1
5 changed files with 41 additions and 12 deletions

View file

@ -2,10 +2,11 @@ import "reflect-metadata";
import express, { NextFunction, Request, Response } from "express";
import dotenv from "dotenv";
import { AppDataSource } from "./data-source.js";
import authRoutes from "./endpoints/AuthPoint.js";
import authRoutes, { authBasicRoute } from "./endpoints/AuthPoint.js";
import userRoutes from "./endpoints/UserPoint.js";
// import recipeRoutes from "./endpoints/RecipePoint.js";
import { errorHandler } from "./middleware/errorHandler.js";
import { authentication } from "./middleware/authenticationMiddleware.js";
dotenv.config();
@ -15,16 +16,19 @@ app.use(errorHandler);
async function startServer() {
try {
// 1 Initialize database
// Initialize database
await AppDataSource.initialize();
console.log("Data Source initialized");
// Optional: run pending migrations
// Run pending migrations
await AppDataSource.runMigrations();
console.log("Migrations executed");
// 2⃣ Setup routes
app.use("/auth", authRoutes);
// Activate Authentication
app.use(authentication);
// Setup routes
app.use(authBasicRoute, authRoutes);
app.use("/user", userRoutes);
// app.use("/recipe", recipeRoutes);
@ -34,7 +38,7 @@ async function startServer() {
});
console.log("Routes set up")
// 3 Start listening
// Start listening
const PORT = Number(process.env.PORT) || 4000;
const HOST = process.env.HOST || "localhost";