add athorization to all calls except auth
This commit is contained in:
parent
8fb48f7243
commit
5dd79374c1
5 changed files with 41 additions and 12 deletions
16
src/index.ts
16
src/index.ts
|
|
@ -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";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue