mirror of
https://github.com/20kaushik02/spotify-manager.git
synced 2026-01-25 06:04:05 +00:00
setting up stuff
This commit is contained in:
20
boilerplates/controller.js
Normal file
20
boilerplates/controller.js
Normal file
@@ -0,0 +1,20 @@
|
||||
require('dotenv').config();
|
||||
|
||||
const typedefs = require("../typedefs");
|
||||
|
||||
/**
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
*/
|
||||
const __controller_func = async (req, res) => {
|
||||
try {
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).send({ message: "Server Error. Try again." });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
__controller_func
|
||||
};
|
||||
13
boilerplates/route.js
Normal file
13
boilerplates/route.js
Normal file
@@ -0,0 +1,13 @@
|
||||
const router = require('express').Router();
|
||||
|
||||
const validator = require("../validators");
|
||||
|
||||
router.get(
|
||||
|
||||
);
|
||||
|
||||
router.post(
|
||||
|
||||
);
|
||||
|
||||
module.exports = router;
|
||||
22
boilerplates/validator.js
Normal file
22
boilerplates/validator.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const { body, header, param, query } = require("express-validator");
|
||||
|
||||
const typedefs = require("../typedefs");
|
||||
|
||||
/**
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
* @param {typedefs.Next} next
|
||||
*/
|
||||
const __validator_func = async (req, res, next) => {
|
||||
await body('field_name')
|
||||
.notEmpty()
|
||||
.withMessage('field_name not defined in body')
|
||||
.run(req);
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
__validator_func,
|
||||
}
|
||||
|
||||
28
index.js
Normal file
28
index.js
Normal file
@@ -0,0 +1,28 @@
|
||||
require('dotenv').config();
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const cookieParser = require('cookie-parser');
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(cors());
|
||||
app.use(cookieParser());
|
||||
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
app.use(express.static(__dirname + '/public'));
|
||||
|
||||
app.use("/api/auth/", require("./routes/auth"));
|
||||
|
||||
app.use((_req, res) => {
|
||||
return res.status(404).send(
|
||||
"Oops! You're not supposed to know about <a href=\"https://github.com/20kaushik02/spotify-manager\">this</a>..."
|
||||
);
|
||||
})
|
||||
|
||||
const port = process.env.PORT || 3000;
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`App Listening on port ${port}`);
|
||||
});
|
||||
2528
package-lock.json
generated
Normal file
2528
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
32
package.json
Normal file
32
package.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "spotify-manager",
|
||||
"version": "1.0.0",
|
||||
"description": "Personal Spotify playlist manager",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "node index.js",
|
||||
"dev": "nodemon index.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/20kaushik02/spotify-manager.git"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/20kaushik02/spotify-manager/issues"
|
||||
},
|
||||
"homepage": "https://github.com/20kaushik02/spotify-manager#readme",
|
||||
"dependencies": {
|
||||
"cookie-parser": "^1.4.6",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.0.1",
|
||||
"express": "^4.18.1",
|
||||
"express-validator": "^6.14.2",
|
||||
"got": "^12.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.13",
|
||||
"nodemon": "^2.0.19"
|
||||
}
|
||||
}
|
||||
7
typedefs.js
Normal file
7
typedefs.js
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @typedef {import('express').Request} Req
|
||||
* @typedef {import('express').Response} Res
|
||||
* @typedef {import('express').NextFunction} Next
|
||||
*/
|
||||
|
||||
exports.unused = {};
|
||||
27
validators/index.js
Normal file
27
validators/index.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const { validationResult } = require("express-validator");
|
||||
|
||||
const typedefs = require("../typedefs");
|
||||
|
||||
/**
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
* @param {typedefs.Next} next
|
||||
*/
|
||||
const validate = (req, res, next) => {
|
||||
const errors = validationResult(req);
|
||||
if (errors.isEmpty()) {
|
||||
return next();
|
||||
}
|
||||
const extractedErrors = []
|
||||
errors.array().map(err => extractedErrors.push({
|
||||
[err.param]: err.msg
|
||||
}));
|
||||
|
||||
return res.status(400).json({
|
||||
message: extractedErrors,
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
validate,
|
||||
}
|
||||
Reference in New Issue
Block a user