-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
31 lines (24 loc) · 898 Bytes
/
main.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
import koa, { Context, DefaultState, Next } from "koa";
import serve from "koa-static";
import views from "koa-views";
import dotenv from "dotenv";
import homeRouter from "./routes/home.route";
import blogRouter from "./routes/blog.route";
import seriesRouter from "./routes/series.route";
dotenv.config();
const PORT = process.env.PORT || 3000;
const app = new koa({ proxy: true });
// ejs template engine
const render = views("./views", {
extension: "ejs",
});
app.use(render);
// serve static files
app.use(serve("./public"));
app.use(homeRouter.allowedMethods()).use(homeRouter.routes());
app.use(blogRouter.allowedMethods()).use(blogRouter.routes());
app.use(seriesRouter.allowedMethods()).use(seriesRouter.routes());
app.use(async (ctx: Context) => {
await ctx.render("404", { url: ctx.url, ip: ctx.ip });
});
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));