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
| const express = require('express') const app = express() const bodyParser = require('body-parser')
app.use((req, res, next) => { res.header('Access-Control-Allow-Origin','*'); res.header('Access-Control-Allow-Credential','true'); res.header('Access-Control-Allow-Methods','GET,POST,PUT,DELETE,OPTIONS'); next(); })
app.use(bodyParser.urlencoded({extended:false}))
app.get('/login', (req,res) => { res.send({msg: 'success', code: 200, data:{name:req.query.name}}) })
app.post('/login', (req,res) => { res.send({msg: 'success', code: 200, data:{pwd:req.body.pwd}}) })
app.listen(3000, () => { console.log("server start") })
|