-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,061 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ import cors from 'cors' | |
import * as url from 'url' | ||
import cookieParser from 'cookie-parser' | ||
import { ErrorMiddleware } from './src/middlewares/error.middleware.js' | ||
import swaggerJSDoc from 'swagger-jsdoc' | ||
import swaggerUi from 'swagger-ui-express' | ||
|
||
loadEnv() | ||
|
||
|
@@ -28,7 +30,7 @@ export class App { | |
this.initializeFrontend() | ||
this.initializeMiddlewares() | ||
this.initializeRoutes(routes) | ||
// this.initializeSwagger(); | ||
this.initializeSwagger() | ||
this.initializeErrorHandling() | ||
} | ||
|
||
|
@@ -46,12 +48,12 @@ export class App { | |
} | ||
|
||
initializeFrontend() { | ||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url)) | ||
// Use build folder for static files | ||
this.app.use(express.static('build')) | ||
this.app.get('/env', exposeEnvMiddleware(loadPublicEnv)) | ||
|
||
// TODO ADD ERROR HANDLING FOR UNKNOWN ROUTES | ||
// const __dirname = url.fileURLToPath(new URL('.', import.meta.url)) | ||
// this.app.get('*', (req, res) => | ||
// res.sendFile(path.join(__dirname, '../', '/build/index.html')) | ||
// ) | ||
|
@@ -99,21 +101,37 @@ export class App { | |
|
||
initializeRoutes(routes) { | ||
routes.forEach((route) => { | ||
this.app.use('/api', route.router) | ||
this.app.use('/api/v1', route.router) | ||
}) | ||
} | ||
|
||
initializeSwagger() { | ||
const swaggerPath = path.resolve('be', 'src', 'routes', '*') | ||
console.log(swaggerPath) | ||
const options = { | ||
swaggerDefinition: { | ||
definition: { | ||
openapi: '3.0.0', | ||
info: { | ||
title: 'REST API', | ||
title: 'Veritext Express API', | ||
version: '1.0.0', | ||
description: 'Example docs', | ||
description: | ||
'Veritet Express API with autogenerated swagger documentation', | ||
contact: { | ||
name: 'Launchpad Lab', | ||
url: 'https://launchpadlab.com/', | ||
email: '[email protected]', | ||
}, | ||
}, | ||
servers: [ | ||
{ | ||
url: 'http://localhost:3000', | ||
basepath: '/api/v1', | ||
}, | ||
], | ||
}, | ||
apis: ['swagger.yaml'], | ||
apis: [swaggerPath], | ||
} | ||
|
||
const specs = swaggerJSDoc(options) | ||
this.app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs)) | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,62 @@ | ||
/** | ||
* @swagger | ||
* components: | ||
* schemas: | ||
* User: | ||
* type: object | ||
* required: | ||
* properties: | ||
* id: | ||
* type: string | ||
* description: The auto-generated id of the book | ||
* email: | ||
* type: string | ||
* description: users email | ||
* admin: | ||
* type: boolean | ||
* description: if the user is an admin | ||
* activities: | ||
* type: array | ||
* description: The activities the user has completed | ||
* createdAt: | ||
* type: string | ||
* format: date | ||
* description: The date the user was added | ||
* example: | ||
* id: d5fE_asz | ||
* email: [email protected] | ||
* admin: true | ||
* activities: [1, 2, 3] | ||
* createdAt: 2020-03-10T04:05:06.157Z | ||
*/ | ||
/** | ||
* @swagger | ||
* tags: | ||
* name: Users | ||
* description: Users management and retrieval | ||
* /users: | ||
* get: | ||
* summary: Get all users | ||
* tags: [Users] | ||
* requestBody: | ||
* required: false | ||
* content: | ||
* application/json: | ||
* schema: | ||
* $ref: '#/components/schemas/User' | ||
* responses: | ||
* 200: | ||
* description: Users Retrieved. | ||
* content: | ||
* application/json: | ||
* schema: | ||
* $ref: '#/components/schemas/User' | ||
* 500: | ||
* description: Some server error | ||
* | ||
*/ | ||
|
||
import { Router } from 'express' | ||
import { UsersController } from '../controllers/users.controller.js' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
tags: | ||
- name: users | ||
description: users API | ||
|
||
paths: | ||
# [GET] users | ||
/users: | ||
get: | ||
tags: | ||
- users | ||
summary: Find All Users | ||
responses: | ||
200: | ||
description: 'OK' | ||
500: | ||
description: 'Server Error' | ||
|
||
# [POST] users | ||
post: | ||
tags: | ||
- users | ||
summary: Add User | ||
parameters: | ||
- name: body | ||
in: body | ||
description: user Data | ||
required: true | ||
schema: | ||
$ref: '#/definitions/users' | ||
responses: | ||
201: | ||
description: 'Created' | ||
400: | ||
description: 'Bad Request' | ||
409: | ||
description: 'Conflict' | ||
500: | ||
description: 'Server Error' | ||
|
||
# [GET] users/id | ||
/users/{id}: | ||
get: | ||
tags: | ||
- users | ||
summary: Find User By Id | ||
parameters: | ||
- name: id | ||
in: path | ||
description: User Id | ||
required: true | ||
type: integer | ||
responses: | ||
200: | ||
description: 'OK' | ||
409: | ||
description: 'Conflict' | ||
500: | ||
description: 'Server Error' | ||
|
||
# [PUT] users/id | ||
put: | ||
tags: | ||
- users | ||
summary: Update User By Id | ||
parameters: | ||
- name: id | ||
in: path | ||
description: user Id | ||
required: true | ||
type: integer | ||
- name: body | ||
in: body | ||
description: user Data | ||
required: true | ||
schema: | ||
$ref: '#/definitions/users' | ||
responses: | ||
200: | ||
description: 'OK' | ||
400: | ||
description: 'Bad Request' | ||
409: | ||
description: 'Conflict' | ||
500: | ||
description: 'Server Error' | ||
|
||
# [DELETE] users/id | ||
delete: | ||
tags: | ||
- users | ||
summary: Delete User By Id | ||
parameters: | ||
- name: id | ||
in: path | ||
description: user Id | ||
required: true | ||
type: integer | ||
responses: | ||
200: | ||
description: 'OK' | ||
409: | ||
description: 'Conflict' | ||
500: | ||
description: 'Server Error' | ||
|
||
# definitions | ||
definitions: | ||
users: | ||
type: object | ||
required: | ||
- password | ||
properties: | ||
email: | ||
type: string | ||
description: user Email | ||
password: | ||
type: string | ||
description: user Password | ||
|
||
schemes: | ||
- https | ||
- http |
Oops, something went wrong.