Skip to content

Commit

Permalink
update middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
gladwindos committed Mar 19, 2024
1 parent d8d0d1e commit 1d42c3d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .changeset/five-snails-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@gateweaver/server": patch
"@gateweaver/cli": patch
"@gateweaver/policies": patch
---

Update packages
4 changes: 2 additions & 2 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
"ajv-formats": "^2.1.1",
"dotenv": "^16.4.5",
"express": "^4.18.3",
"express-jwt": "^8.4.1",
"helmet": "^7.1.0",
"http-proxy-middleware": "^2.0.6",
"pino": "^8.19.0",
"pino-pretty": "^10.3.1",
"yaml": "^2.3.4"
},
"devDependencies": {
"@types/express": "^4.17.21",
"express-jwt": "^8.4.1"
"@types/express": "^4.17.21"
}
}
6 changes: 3 additions & 3 deletions packages/server/src/middleware/error-handler.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export const errorHandler = (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
next: NextFunction,
) => {
logger.error(err);

if (err instanceof UnauthorizedError) {
res.status(401).send({
error: "Invalid Token",
error: "Invalid Authorization Token",
});
return;
}
Expand All @@ -24,8 +26,6 @@ export const errorHandler = (
return;
}

logger.error(err);

return res.status(500).send({
error: "Internal Server Error",
});
Expand Down
4 changes: 3 additions & 1 deletion packages/server/src/middleware/http-logger.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Request, Response, NextFunction } from "express";
import { logger } from "../utils";

export const httpLogger = (req: Request, res: Response, next: NextFunction) => {
logger.info(`[${req.method}] ${req.originalUrl} - ${res.statusCode}`);
res.on("finish", () => {
logger.info(`[${req.method}] ${req.originalUrl} - ${res.statusCode}`);
});
next();
};
4 changes: 2 additions & 2 deletions packages/server/src/utils/start-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export const startServer = (filePath: string = "gateweaver") => {

app.use(express.json());

app.use(httpLogger);

const router = createRouter(config);
app.use(router);

app.use(errorHandler);

app.use(httpLogger);

app.listen(PORT, () => {
logger.info(`Gateweaver is running on port ${PORT}`);
});
Expand Down
23 changes: 20 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1d42c3d

Please sign in to comment.