-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
51 lines (42 loc) · 1.11 KB
/
index.js
File metadata and controls
51 lines (42 loc) · 1.11 KB
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
45
46
47
48
49
50
51
// const http = require('http')
// const server = http.createServer((req, res) => {
// res.writeHead(200)
// res.end('hello nodejs')
// })
// server.listen(3000, () => {
// console.log('server started at port 3000')
// })
const Moa = require('./moa')
const app = new Moa()
// app.use((req, res) => {
// res.writeHeader(200)
// res.end('hello, Moa')
// })
// app.use(ctx => {
// ctx.body = 'Cool, Moa'
// })
// const delay = () => new Promise(resolve => setTimeout(() => resolve()
// , 2000))
// app.use(async (ctx, next) => {
// ctx.body = "1"
// await next()
// ctx.body += "5"
// })
// app.use(async (ctx, next) => {
// ctx.body += "2"
// await delay()
// await next()
// ctx.body += "4"
// })
// app.use(async (ctx, next) => {
// ctx.body += "3"
// })
const Router = require('./router')
const router = new Router()
router.get('/', async ctx => { ctx.body = 'index page' })
router.get('/home', async ctx => { ctx.body = 'home page' })
router.post('/', async ctx => { ctx.body = 'post index' })
app.use(router.routes())
app.listen(3000, () => {
console.log('server started at port 3000')
})