in progress: integrate swagger, db reconfig
This commit is contained in:
2004
package-lock.json
generated
2004
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"start": "node server.js"
|
"start": "nodemon server.js"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "v16.13.1"
|
"node": "v16.13.1"
|
||||||
@@ -21,13 +21,16 @@
|
|||||||
"express": "^4.17.3",
|
"express": "^4.17.3",
|
||||||
"express-session": "^1.17.3",
|
"express-session": "^1.17.3",
|
||||||
"helmet": "^5.1.0",
|
"helmet": "^5.1.0",
|
||||||
|
"js-yaml": "^4.1.0",
|
||||||
"oauth2-server": "^3.1.1",
|
"oauth2-server": "^3.1.1",
|
||||||
"passport": "^0.6.0",
|
"passport": "^0.6.0",
|
||||||
"passport-local": "^1.0.0",
|
"passport-local": "^1.0.0",
|
||||||
"pg": "^8.7.3",
|
"pg": "^8.7.3",
|
||||||
|
"swagger-ui-express": "^4.4.0",
|
||||||
"uuid": "^8.3.2"
|
"uuid": "^8.3.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/uuid": "^8.3.4"
|
"@types/uuid": "^8.3.4",
|
||||||
|
"nodemon": "^2.0.18"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ productsRouter.route('/:id').get(async (req, res) => {
|
|||||||
// post a product from req.body
|
// post a product from req.body
|
||||||
productsRouter.route('/').post(async (req, res) => {
|
productsRouter.route('/').post(async (req, res) => {
|
||||||
const newClient = client();
|
const newClient = client();
|
||||||
const { name, description, category, categoryID } = req.body;
|
const { name, description, category, categoryID, price } = req.body;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
newClient.connect((err) => {
|
newClient.connect((err) => {
|
||||||
@@ -51,7 +51,7 @@ productsRouter.route('/').post(async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await newClient.query(("INSERT INTO products (name, description, category, category_id) VALUES ($1, $2, $3, $4)"), [name, description, category, categoryID]);
|
await newClient.query(("INSERT INTO products (name, description, category, category_id, price) VALUES ($1, $2, $3, $4, $5)"), [name, description, category, categoryID, price]);
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const app = express();
|
|||||||
const session = require('express-session');
|
const session = require('express-session');
|
||||||
|
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
const PORT = process.env.PORT;
|
const PORT = process.env.PORT || 8088;
|
||||||
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
@@ -28,4 +28,6 @@ app.use(apiRouter);
|
|||||||
|
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
console.log(`Listening on port ${PORT}`);
|
console.log(`Listening on port ${PORT}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
module.exports = app;
|
||||||
11
swagger/swagger.js
Normal file
11
swagger/swagger.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
const swaggerUI = require('swagger-ui-express');
|
||||||
|
const yaml = require('js-yaml');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
// Loading via yml.safeLoad to avoid errors with special characters during processing
|
||||||
|
const swaggerDocument = yaml.safeLoad(fs.readFileSync(path.resolve(__dirname, '../swagger.yml'), 'utf8'));
|
||||||
|
|
||||||
|
const app = require('../server');
|
||||||
|
|
||||||
|
app.use('/api-docs', swaggerUI.serve, swaggerUI.setup(swaggerDocument));
|
||||||
9
swagger/swagger.json
Normal file
9
swagger/swagger.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"openapi": "3.0.3",
|
||||||
|
"info": {
|
||||||
|
"title": "E-Commerce Project",
|
||||||
|
"description": "Full Stack Portfolio project built using Postgres, Express, React and TypeScript",
|
||||||
|
"version": "0.0.1"
|
||||||
|
},
|
||||||
|
"paths": {}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user