feat: create basic express server with swagger documentation
This commit is contained in:
25
src/app.ts
Normal file
25
src/app.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import * as express from 'express';
|
||||
import router from './routes';
|
||||
|
||||
const app = express();
|
||||
|
||||
const swaggerJsdocOpts = {
|
||||
failOnErrors: true,
|
||||
definition: {
|
||||
openapi: '3.0.0',
|
||||
info: {
|
||||
title: 'kittyurl',
|
||||
version: '0.0.1'
|
||||
}
|
||||
},
|
||||
apis: ['./src/routes/*.ts']
|
||||
};
|
||||
const swaggerUi = require('swagger-ui-express');
|
||||
const swaggerJsdoc = require('swagger-jsdoc');
|
||||
const swaggerSpec = swaggerJsdoc(swaggerJsdocOpts);
|
||||
|
||||
app.use(express.json());
|
||||
app.use(router);
|
||||
app.use('/swagger', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
|
||||
app.listen(6567, () => console.log('(HTTP Server) Listening on port 6567.'));
|
||||
|
||||
20
src/routes/index.ts
Normal file
20
src/routes/index.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Router } from 'express';
|
||||
|
||||
const router = Router();
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
*
|
||||
* /:
|
||||
* get:
|
||||
* description: Hello world!
|
||||
* tags: [Default]
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Returns "Hello world!"
|
||||
*/
|
||||
router.get('/', (req, res) => {
|
||||
res.send("Hello world!");
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user