forked from Prolifode/deno_rest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
33 lines (25 loc) · 810 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
29
30
31
32
33
import { Application, oakCors } from "./deps.ts";
import { errorHandler } from "./middlewares/errorHandler.middleware.ts";
import log from "./middlewares/logger.middleware.ts";
import configs from "./config/config.ts";
import router from "./routers/index.ts";
const { env, url, port, clientUrl } = configs;
const app: Application = new Application();
const corsOptions = {
"origin": clientUrl,
"methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
"preflightContinue": false,
"optionsSuccessStatus": 200,
"credentials": true,
};
app.use(oakCors(corsOptions));
app.use(errorHandler);
router.init(app);
app.addEventListener("listen", () => {
log.info(`Current Environment: ${env}`);
log.info(`Server listening at ${url}`);
});
if (import.meta.main) {
await app.listen({ port });
}
export { app };