-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
44 lines (37 loc) · 1.29 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { Application, isHttpError, Status } from "./dependencies.ts";
//Importando rutas
import userRoutes from "./routes/userRoutes.ts";
import loginRoutes from "./routes/loginRoutes.ts";
import accountRoutes from "./routes/accountRoutes.ts";
import transactionRoutes from "./routes/transactionRoutes.ts";
const app = new Application();
app.use(async (context, next) => {
try {
await next();
}catch (err){
console.log(err);
if(isHttpError(err)){
switch(err.status){
case Status.UnsupportedMediaType:
context.response.body = {data: "La petición no posee el encabezado Content-Type."};
context.response.status = 400;
break;
}
}else{
//Si no es un error de la petición, es del servidor.
context.response.body = {data: "Error interno del servidor."};
context.response.status = 500;
}
return;
}
});
//Cargando rutas
app.use(userRoutes.routes());
app.use(userRoutes.allowedMethods());
app.use(loginRoutes.routes());
app.use(loginRoutes.allowedMethods());
app.use(accountRoutes.routes());
app.use(accountRoutes.allowedMethods());
app.use(transactionRoutes.routes());
app.use(transactionRoutes.allowedMethods());
export {app};