Created
October 8, 2018 01:50
-
-
Save xhsdnn/57d2d28182273f36c02206a32146ee4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var app = express(); | |
app.use(express.static('dist')); | |
//设置跨域访问 | |
app.all('*', function(req, res, next) { | |
res.header("Access-Control-Allow-Origin", "*"); | |
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); | |
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS"); | |
res.header("X-Powered-By",' 3.2.1') | |
res.header("Content-Type", "application/json;charset=utf-8"); | |
next(); | |
}); | |
// 测试 | |
app.get('/userLogin', function(req, res){ | |
res.send('request is success hahaha...'); | |
//关闭连接 | |
connection.end(); | |
}); | |
app.post('/userLogin', function(req, res){ | |
res.send('request is success aaaaa...'); | |
//关闭连接 | |
connection.end(); | |
}); | |
app.listen(8084); | |
console.log('Listening on port 8084...'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment