feat: init-express-backend #6

Merged
Clement merged 38 commits from feat--init-express-backend into master 2024-05-06 19:20:30 +00:00
3 changed files with 47 additions and 7 deletions
Showing only changes of commit e69773fdd6 - Show all commits

View File

@ -1,23 +1,32 @@
import express from "express";
import express from "express"
/**
* Initialize Express application instance.
* @returns An initialized Express application object.
*/
const app = express();
const app = express()
/**
* Handle GET request for homepage route ('/').
* Handle GET request for homepage route ('/welcome').
* Send back a simple json response.
* @param {express.Request} req - HTTP Request object.
* @param {express.Response} res - HTTP Response object.
*/
function getWelcome(req: express.Request, res: express.Response) {
const out = {hello:"world"};
res.send(out);
const out = {hello:"world"}
res.send(out)
}
app.get("/welcome", getWelcome);
/**
* @openapi
* /welcome:
* get:
* description: Welcome to swagger-jsdoc!
* responses:
* 200:
* description: Returns a welcome json.
*/
app.get("/welcome", getWelcome)
export default app;
export default app

View File

@ -1,10 +1,16 @@
import * as dotenv from "dotenv";
import app from "./app";
import options from "./swaggerDef";
const swaggerJsdoc = require("swagger-jsdoc"),
swaggerUi = require("swagger-ui-express");
dotenv.config({path: '../../.env'})
const port = parseInt(process.env.BAR_PORT || '3000')
const specs = swaggerJsdoc(options)
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(specs))
app.listen(port, () =>{
console.log(`serveur running in ${port}`)
})

View File

@ -0,0 +1,25 @@
import * as dotenv from "dotenv";
dotenv.config({path: '../../.env'})
const port = parseInt(process.env.BAR_PORT || '3000')
const options = {
definition: {
openapi: "3.1.0",
info: {
title: "LogRocket Express API with Swagger",
version: "0.1.0",
description:
"This is a simple CRUD API application made with Express and documented with Swagger",
},
servers: [
{
url: "http://localhost:"+port.toString(),
},
],
},
apis: ['./src/*.ts'],
}
export default options