Node.js+koa2
const Koa = require('koa')
const app = new Koa()
const bodyParser = require('koa-bodyparser')
app.use(bodyParser())
app.use(async (ctx) => {
if (ctx.url === '/' && ctx.method === 'GET') {
let html = `
<h2>This is demo</h2>
<form method="POST" action="/">
<p>username:</p>
<input name="username">
<p>age:</p>
<input name="age">
<p>website</p>
<input name="website">
<button type="submit">submit</button>
</form>
`
ctx.body = html
} else if (ctx.url === '/' && ctx.method === 'POST') {
let postData = ctx.request.body;
ctx.body = postData
} else {
ctx.body = '<h2>Not find</h2>'
}
})
app.listen(3000, () => {
console.log('demo is run')
})github地址:https://github.com/Rossy11/node
相关推荐
往后余生 2020-09-17
yanyongtao 2020-11-02
lzccheng 2020-09-06
webgm 2020-08-16
lert0 2020-08-16
80447704 2020-06-09
LorenLiu 2020-06-07
无缘公子 2020-02-02
LorenLiu 2020-01-31
LorenLiu 2020-01-30
80447704 2020-01-30
苏莉koa 2020-01-29
Qimingweikun 2020-01-28
80447704 2020-01-02
byourb 2020-01-04
80447704 2019-12-24