mirror of
https://github.com/bubblecup-12/VogelSocialMedia.git
synced 2025-07-08 03:28:50 +00:00
added authentication and swagger
This commit is contained in:
parent
c311e3adda
commit
64c0d79438
8 changed files with 447 additions and 56 deletions
|
@ -1,4 +1,4 @@
|
|||
import express, { Request, Response } from "express";
|
||||
import express, { Request, Response, Application } from "express";
|
||||
|
||||
import dotenv from "dotenv";
|
||||
import userRouter from "./routes/userRoutes";
|
||||
|
@ -9,9 +9,50 @@ dotenv.config();
|
|||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
//swagger configuration
|
||||
import swaggerJSDoc from "swagger-jsdoc";
|
||||
import swaggerUi from "swagger-ui-express";
|
||||
|
||||
const options = {
|
||||
definition: {
|
||||
openapi: "3.1.0",
|
||||
info: {
|
||||
title: "VogelApi",
|
||||
version: "0.0.1",
|
||||
description:
|
||||
"This is a simple CRUD API application made with Express and documented with Swagger",
|
||||
},
|
||||
servers: [
|
||||
{
|
||||
url: "http://localhost:3000",
|
||||
},
|
||||
],
|
||||
components: {
|
||||
securitySchemes: {
|
||||
bearerAuth: {
|
||||
type: "http",
|
||||
scheme: "bearer",
|
||||
bearerFormat: "JWT", // Optional, for documentation purposes
|
||||
},
|
||||
},
|
||||
},
|
||||
security: [
|
||||
{
|
||||
bearerAuth: [], // Apply globally if needed
|
||||
},
|
||||
],
|
||||
},
|
||||
apis: ["src/routes/*.ts"], // Hier werden alle Routen-Dateien mit Swagger-Kommentaren geladen
|
||||
};
|
||||
const specs = swaggerJSDoc(options);
|
||||
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(specs));
|
||||
|
||||
app.use(bodyParser.json());
|
||||
app.use("/api/user", userRouter);
|
||||
|
||||
// Sample route
|
||||
app.get("/api/hello", (req, res) => {
|
||||
res.send("Hello World!");
|
||||
});
|
||||
app.listen(port, () => {
|
||||
console.log(`Server läuft auf http://localhost:${port}`);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue