mirror of
https://github.com/GithubOrgProjectPiza/server.git
synced 2026-09-04 08:36:10 +02:00
Add json body parser; Add default response for errors
This commit is contained in:
Generated
+1231
-56
File diff suppressed because it is too large
Load Diff
@@ -20,11 +20,18 @@
|
|||||||
"homepage": "https://github.com/GithubOrgProjectPiza/server#readme",
|
"homepage": "https://github.com/GithubOrgProjectPiza/server#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@prisma/client": "^3.10.0",
|
"@prisma/client": "^3.10.0",
|
||||||
|
"@types/argon2": "^0.15.0",
|
||||||
"@types/express": "^4.17.13",
|
"@types/express": "^4.17.13",
|
||||||
|
"@types/jsonwebtoken": "^8.5.8",
|
||||||
"@types/nodemailer": "^6.4.4",
|
"@types/nodemailer": "^6.4.4",
|
||||||
|
"argon2": "^0.28.5",
|
||||||
"dotenv": "^16.0.0",
|
"dotenv": "^16.0.0",
|
||||||
"express": "^4.17.3",
|
"express": "^4.17.3",
|
||||||
|
<<<<<<< HEAD
|
||||||
"nodemailer": "^6.7.2",
|
"nodemailer": "^6.7.2",
|
||||||
|
=======
|
||||||
|
"jsonwebtoken": "^8.5.1",
|
||||||
|
>>>>>>> a1fd598 (Add json body parser; Add default response for errors)
|
||||||
"prisma": "^3.10.0",
|
"prisma": "^3.10.0",
|
||||||
"ts-node": "^10.5.0",
|
"ts-node": "^10.5.0",
|
||||||
"typescript": "^4.5.5"
|
"typescript": "^4.5.5"
|
||||||
|
|||||||
+19
-1
@@ -1,15 +1,33 @@
|
|||||||
import express from "express";
|
import express, { NextFunction, Request, Response } from "express";
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
|
import adminRoutes from "./routes/auth.route";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
// Bodyparser and urlencoded to parse post request bodies
|
||||||
|
app.use(express.urlencoded({ extended: true }));
|
||||||
|
app.use(express.json());
|
||||||
|
|
||||||
|
app.use((err: any, req: Request, res: Response, next: NextFunction) => {
|
||||||
|
if (err) {
|
||||||
|
res.status(400).send({
|
||||||
|
type: "error",
|
||||||
|
payload: "The body of your request did not contain valid data",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
app.get("/", (req, res) => {
|
app.get("/", (req, res) => {
|
||||||
res.send("Hello World!");
|
res.send("Hello World!");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use("/api/auth", adminRoutes);
|
||||||
|
|
||||||
app.listen(3000, () => {
|
app.listen(3000, () => {
|
||||||
console.log("Server is running on port 3000");
|
console.log("Server is running on port 3000");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
export const createDefaultError = (message: string, context: any) => ({
|
||||||
|
"type": "error",
|
||||||
|
"payload": {
|
||||||
|
"message": message,
|
||||||
|
"context": context,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export const createDefaultSucces = (message: string, context: any) => ({
|
||||||
|
"type": "success",
|
||||||
|
"payload": {
|
||||||
|
"message": message,
|
||||||
|
"context": context,
|
||||||
|
}
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user