finished user store in typscript

This commit is contained in:
canove
2020-09-14 18:54:36 -03:00
parent eba3553a2d
commit 7f33e33078
29 changed files with 260 additions and 133 deletions

View File

@@ -1,7 +1,8 @@
import "dotenv/config";
import "express-async-errors";
import express from "express";
import express, { Request, Response, NextFunction } from "express";
import cors from "cors";
import AppError from "./errors/AppError";
import routes from "./routes";
@@ -15,14 +16,21 @@ import "./database";
// const wbotMonitor = require("./services/wbotMonitor");
// const Whatsapp = require("./models/Whatsapp");
// const Router = require("./router");
const app = express();
app.use(cors());
app.use(express.json());
app.use(routes);
app.use(async (err: Error, req: Request, res: Response, next: NextFunction) => {
if (err instanceof AppError) {
return res.status(err.statusCode).json({ error: err.message });
}
console.error(err);
return res.status(500).json({ error: "Internal server error" });
});
const server = app.listen(process.env.PORT, () => {
console.log(`Server started on port: ${process.env.PORT}`);
});