Merge branch 'dev' into feature-email-verification

This commit is contained in:
Stefan
2022-04-29 11:40:28 +02:00
committed by GitHub
8 changed files with 184 additions and 19 deletions
+23 -11
View File
@@ -11,11 +11,21 @@ import argon2 from "argon2";
import adminRouter from "./Routes/admin.routes";
import organisationRouter from "./Routes/organisation.routes";
import groupRouter from "./Routes/group.routes";
import defaultErrorHandler from "./Middleware/error/handler";
import logger from "./Middleware/error/logger";
import debugLogger from "./Middleware/debug/logger";
// Set up async error handling
require("express-async-errors");
require("dotenv").config(); // Load dotenv config
const app = express();
if (process.env.NODE_ENV === "development") {
logger.info("Using development mode");
}
async function main() {
// Dev
await prisma.admin.upsert({
@@ -34,16 +44,7 @@ async function main() {
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();
}
});
app.use(debugLogger);
// Admin authentication endpoints
app.use("/api/authentication", adminAuthRouter);
@@ -56,13 +57,24 @@ async function main() {
app.use("/api/organisations", organisationRouter);
app.use("/api/groups", groupRouter);
// Error handling
app.use(defaultErrorHandler);
app.listen(process.env.PORT, () => {
console.log(`Listening on Port: ${process.env.PORT}`);
logger.info(`Listening on port ${process.env.PORT}`);
});
logger.info("Server started");
process.on("exit", () => {
logger.info("Server stopping...");
});
}
main()
.catch((e) => {
logger.crit(e);
throw e;
})
.finally(async () => {