-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
28 lines (22 loc) · 803 Bytes
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import express, { NextFunction, Request, Response } from "express";
import http from "http";
import morgan from "morgan";
import { GenericError } from "./models/error";
import { bucketRouter } from "./modules/s3";
const app = express();
app.use(express.json());
app.use(morgan('dev'));
// Routes
app.use(bucketRouter.PREFIX, bucketRouter.getRouter());
// Error Handling
app.use((err: any, req: Request, resp: Response, next: NextFunction) => {
const error: GenericError = {
statusCode: err.statusCode || '500',
title: err.title || '',
message: err.message || 'Someting goes wrong',
}
resp.status(error.statusCode).send(error)
})
const port = process.env.PORT || 8080;
const server = http.createServer(app)
server.listen(port, () => console.log("Listening..."))