Skip to content

Commit

Permalink
Merge pull request #4 from mrlazyg/dev
Browse files Browse the repository at this point in the history
Updated Server List For Diff Env
  • Loading branch information
noorsalimx authored Mar 7, 2024
2 parents b4cafa0 + 8e7416e commit 63e82a4
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 4 deletions.
15 changes: 12 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const ErrorHandler = require('./utils/ErrorHandler');
const { health } = require('./controllers/Health');
const tourRouter = require('./routes/TourRoutes');
const userRouter = require('./routes/UserRoutes');
const swaggerDoc = require('./swagger/swagger.json');
const swaggerLoc = require('./swagger/swagger_local.json');
const swaggerProd = require('./swagger/swagger_prod.json');
const openAPIDoc = require('./swagger/openapi_1.json');

const swaggerOptions = {
Expand All @@ -26,7 +27,13 @@ app.use(express.json());
app.use(morgan('dev'));
app.use(express.static(`${__dirname}/public`));

app.use('/api/v1/docs', swagger.serve, swagger.setup(swaggerDoc, swaggerOptions)); // serve single swagger document
if (process.env.NODE_ENV === 'production') {
console.log(`App is running on ${process.env.NODE_ENV} server!`);
app.use('/api/v1/docs', swagger.serve, swagger.setup(swaggerProd, swaggerOptions)); // serve single swagger document
} else {
console.log(`App is running on ${process.env.NODE_ENV || 'local'} server!`);
app.use('/api/v1/docs', swagger.serve, swagger.setup(swaggerLoc, swaggerOptions)); // serve single swagger document
}
// serve multiple swagger documents
// app.use('/api/v1/docs', swagger.serveFiles(swaggerDoc), swagger.setup(swaggerDoc, swaggerOptions));
// app.use('/api/v2/docs', swagger.serveFiles(openAPIDoc), swagger.setup(swaggerDoc, swaggerOptions));
Expand All @@ -35,7 +42,9 @@ app.use('/api/v1/tours', tourRouter);
app.use('/api/v1/users', userRouter);

app.get(['/', '/api/health'], health);
app.get(['/api', '/status', '/api/status', '/api/v1', '/api/v1/status'], (req, res) => res.redirect(307, '/'));
app.get(['/api', '/status', '/api/status', '/api/v1', '/api/v1/status'], (req, res) =>
res.redirect(307, '/')
);

app.all('*', (req, res, next) => {
next(new ErrorHandler(`Can't find ${req.originalUrl} on this server!`, 404));
Expand Down
2 changes: 1 addition & 1 deletion swagger/swagger.json → swagger/swagger_local.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"url": "https://opensource.org/licenses/MIT"
}
},
"host": ["localhost:3000", "https://visit-natours.onrender.com"],
"host": ["localhost:3000"],
"basePath": "/api/v1",
"tags": [
{
Expand Down
201 changes: 201 additions & 0 deletions swagger/swagger_prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Natours Tour API Docs",
"description": "This API docs explains the use of APIs",
"license": {
"name": "MIT",
"url": "https://opensource.org/licenses/MIT"
}
},
"host": ["https://visit-natours.onrender.com"],
"basePath": "/api/v1",
"tags": [
{
"name": "Users",
"description": "API for users in the system"
}
],
"schemes": ["http", "https"],
"consumes": ["application/json", "application/xml"],
"produces": ["application/json", "application/xml"],
"paths": {
"/users": {
"post": {
"tags": ["Users"],
"description": "Create new user in system",
"parameters": [
{
"name": "user",
"in": "body",
"description": "User that we want to create",
"schema": {
"$ref": "#/definitions/User"
}
}
],
"responses": {
"200": {
"description": "New user is created",
"schema": {
"$ref": "#/definitions/User"
}
}
}
},
"get": {
"tags": ["Users"],
"summary": "Get all users in system",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Users"
}
}
}
}
},
"/users/{userId}": {
"parameters": [
{
"name": "userId",
"in": "path",
"required": true,
"description": "ID of user that we want to find",
"type": "string"
}
],
"get": {
"tags": ["Users"],
"summary": "Get user with given ID",
"responses": {
"200": {
"description": "User is found",
"schema": {
"$ref": "#/definitions/User"
}
}
}
},
"delete": {
"summary": "Delete user with given ID",
"tags": ["Users"],
"responses": {
"200": {
"description": "User is deleted",
"schema": {
"$ref": "#/definitions/User"
}
}
}
},
"put": {
"summary": "Update user with give ID",
"tags": ["Users"],
"parameters": [
{
"name": "user",
"in": "body",
"description": "User with new values of properties",
"schema": {
"$ref": "#/definitions/User"
}
}
],
"responses": {
"200": {
"description": "User is updated",
"schema": {
"$ref": "#/definitions/User"
}
}
}
}
}
},

"definitions": {
"User": {
"required": ["email", "_id"],
"properties": {
"email": {
"type": "string",
"uniqueItems": true,
"example": "john.doe@example.com"
},
"firstName": {
"type": "string",
"example": "John"
},
"lastName": {
"type": "string",
"example": "Doe"
}
}
},
"Users": {
"type": "array",
"$ref": "#/definitions/User"
},
"Tours": {
"required": [
"name",
"duration",
"price",
"maxGroupSize",
"difficulty",
"summary",
"imageCover"
],
"type": "object",
"properties": {
"name": {
"type": "string",
"uniqueItems": true
},
"duration": {
"type": "number"
},
"price": {
"type": "number"
},
"ratingsAverage": {
"type": "number",
"default": 4
},
"ratingsQuantity": {
"type": "number"
},
"difficulty": {
"type": "string"
},
"discount": {
"type": "number"
},
"summary": {
"type": "string"
},
"description": {
"type": "string",
"example": "Tour Descriptions"
},
"imageCover": {
"type": "string"
},
"images": {
"type": "array",
"items": {
"type": "string"
}
},
"startDates": {
"type": "string",
"format": "date-time",
"example": "2021-08-19T08:37:28Z"
}
}
}
}
}

0 comments on commit 63e82a4

Please sign in to comment.