Skip to content

Commit 5c754e8

Browse files
author
sourabh
committed
Inject - some middleware & swaggerUi
1 parent 192ab3f commit 5c754e8

6 files changed

+221
-14
lines changed

app.js

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
require("dotenv").config();
2-
const express = require('express')
3-
const app = express()
2+
const express = require("express");
3+
const app = express();
4+
const cookieParser = require("cookie-parser");
5+
const fileUpload = require("express-fileupload");
46

5-
// Ref: ✈️🔗https://expressjs.com/en/5x/api.html#router
7+
//SWAGGER DOCUMENTATION
8+
const swaggerUi = require("swagger-ui-express");
9+
const fs = require("fs");
10+
const YAML = require("yamljs");
11+
const file = fs.readFileSync("./swagger.yaml", "utf8");
12+
const swaggerDocument = YAML.parse(file);
13+
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
614

7-
// BRINGS ROUTES
15+
//MORGAN MIDDLEWARE
16+
const morgan = require("morgan");
17+
app.use(morgan("tiny"));
18+
19+
//COOKIES AND FILE-UPLOAD MIDDLEWARE
20+
app.use(cookieParser());
21+
app.use(fileUpload());
22+
23+
//REGULAR MIDDLEWARE
24+
app.use(express.json());
25+
app.use(express.urlencoded({extended:true}))
26+
27+
// BRINGS ROUTES
828
const home = require("./routes/home");
929

1030
// USING MIDDLEWARE
11-
app.use("/api/v1",home);
31+
app.use("/api/v1", home);
1232

13-
module.exports = app;
33+
module.exports = app;

map_project.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
@ABOUT_ROUTES:
3+
Ref: ✈️🔗https://expressjs.com/en/5x/api.html#router
4+
5+
-----------------NEW--------------------
6+
@SECTION:Injecting Docs and MIDDLEWARE
7+
@ABOUT: All about Inject MIDDLEWARE
8+
@TITLE:
9+
@LOCATION:🗃️App.js
10+
11+
@OVERVIEW:->
12+
@REQUERE
13+
-🎗️Need Body-parser for handle JSON
14+
-🎗️Need cookie-parser,swagger,morgan
15+
16+
@ABOUT_MORGAN
17+
Ref: ✈️🔗 https://www.npmjs.com/package/morgan
18+
SCROLL ON till Bottom ...above link
19+
😗@NOTE: NEEDs to be come befoure route it's convection
20+
21+
@INVITE_&_INSTALL:-> MORGAN,cookieParser,fileUpload,swaggerUi & some REGULAR MIDDLEWARE like json & urlencoded
22+
23+
24+
25+
26+
27+
28+
29+
*/

nodemon.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"ext": ".js, .jsx, .yaml"
3+
}

package-lock.json

+104-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
"nodemailer": "^6.9.3",
2727
"razorpay": "^2.8.6",
2828
"stripe": "^12.10.0",
29-
"validator": "^13.9.0"
29+
"swagger-ui-express": "^4.6.3",
30+
"validator": "^13.9.0",
31+
"yamljs": "^0.3.0"
3032
},
3133
"devDependencies": {
3234
"nodemon": "^2.0.22"

swagger.yaml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Tshirt store API
4+
description: A course to create API for ecomm store
5+
version: 1.1.0
6+
contact:
7+
email: sp647600@gmail.com
8+
url: "https://saurabh-pande.netlify.com"
9+
10+
# servers:
11+
# - url: "https://localhost:8000/api/v1"
12+
# description: for local host -secure
13+
# - url: "http://localhost:8000/api/v1"
14+
# description: for local host -regular
15+
16+
servers:
17+
- url: "{protocol}://localhost:8000/api/{version}"
18+
description: for local host -secure
19+
variables:
20+
version:
21+
enum:
22+
- v1
23+
- v2
24+
default: v1
25+
protocol:
26+
enum:
27+
- http
28+
- https
29+
default: http
30+
components:
31+
securitySchemes:
32+
cookieAuth:
33+
type: apiKey
34+
in: cookie
35+
name: token
36+
BearerAuth:
37+
type: http
38+
scheme: bearer
39+
paths:
40+
/d:
41+
get:
42+
tags:
43+
- HOME
44+
summary: return a greet message from LCO
45+
responses:
46+
200:
47+
description: All good success
48+
content:
49+
application/json:
50+
schema:
51+
type: string
52+
example: "mystring"
53+
400:
54+
description: Bad request
55+
500:
56+
description: internal server error

0 commit comments

Comments
 (0)