forked from Xu-pixel/cabbage_server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
25 lines (20 loc) · 865 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
import mongoose from 'npm:mongoose@~6.7'
import commentRoute from './routes/comment.ts'
import UserRoute from './routes/user.ts'
import ArticleRoute from './routes/article.ts'
import { Application } from "https://deno.land/x/[email protected]/mod.ts";
import { CORS } from "https://deno.land/x/[email protected]/mod.ts";
import { ErrorHandler, Logger, Timer } from './Middlewares.ts';
await mongoose.connect(Deno.env.get('MONGO_URL') || 'mongodb://localhost:27017')
const app = new Application();
//注意各个服务的注册顺序
app.use(CORS())
app.use(Logger)
app.use(Timer)
app.use(ErrorHandler)
app.use(commentRoute.prefix('/comment').routes())
app.use(UserRoute.prefix('/user').routes())
app.use(ArticleRoute.prefix('/article').routes())
if (Deno.env.get('DEV'))
console.log('Oak 服务器工作在 http://localhost:8000')
await app.listen({ port: 8000 });