Skip to content

Instantly share code, notes, and snippets.

@xhsdnn
Created October 8, 2018 01:50
Show Gist options
  • Save xhsdnn/57d2d28182273f36c02206a32146ee4d to your computer and use it in GitHub Desktop.
Save xhsdnn/57d2d28182273f36c02206a32146ee4d to your computer and use it in GitHub Desktop.
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