Commit 26280e1d authored by 何硕's avatar 何硕

Merge branch 'heshuo' into 'master'

test wss

See merge request !18
parents 017f7116 81c0bad3
...@@ -2,7 +2,7 @@ var app = require('express')(); ...@@ -2,7 +2,7 @@ var app = require('express')();
var http = require('http').createServer(app); var http = require('http').createServer(app);
var https = require("https"); var https = require("https");
var axios = require('axios'); var axios = require('axios');
var io = require('socket.io')(http); // var io = require('socket.io')(http);
let fs = require("fs"); let fs = require("fs");
...@@ -15,33 +15,39 @@ let fs = require("fs"); ...@@ -15,33 +15,39 @@ let fs = require("fs");
// next(); // next();
// }); // });
//allow custom header and CORS //allow custom header and CORS
app.all('*',function (req, res, next) { // app.all('*',function (req, res, next) {
res.header('Access-Control-Allow-Origin','https://zhibo.xueyoubangedu.com https://livesocket.xueyoubangedu.com'); // res.header('Access-Control-Allow-Origin','https://zhibo.xueyoubangedu.com https://livesocket.xueyoubangedu.com');
res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild'); // res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS'); // res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
if (req.method == 'OPTIONS') { // if (req.method == 'OPTIONS') {
res.send(200); // res.send(200);
} // }
else { // else {
next(); // next();
} // }
}); // });
// var BaseUrl = "http://localhost/api/"; // var BaseUrl = "http://localhost/api/";
var BaseUrl = "https://zhibo.xueyoubangedu.com/api/"; var BaseUrl = "https://zhibo.xueyoubangedu.com/api/";
// var BaseUrl = "https://live.xueyoubangedu.com/api/"; // var BaseUrl = "https://live.xueyoubangedu.com/api/";
const httpsOption = { // const httpsOption = {
key : fs.readFileSync("./https/privkey.pem"), // key : fs.readFileSync("./https/privkey.pem"),
cert: fs.readFileSync("./https/fullchain.pem") // cert: fs.readFileSync("./https/fullchain.pem")
} // }
app.get('/', function(req, res){ app.get('/', function(req, res){
res.send('<h1>Hello world</h1>'); res.send('<h1>Hello world</h1>');
}); });
http.listen(3001, function(){
console.log('http listening on *:3001');
});
var io = require('socket.io')listen(http);
io.on('connection', function(socket){ io.on('connection', function(socket){
console.log("connection"); console.log("connection");
//监听用户登录 //监听用户登录
...@@ -121,10 +127,8 @@ io.on('connection', function(socket){ ...@@ -121,10 +127,8 @@ io.on('connection', function(socket){
}); });
http.listen(3001, function(){
console.log('http listening on *:3001');
});
https.createServer(httpsOption, app).listen(3000, function(){
console.log('https listening on *:3000'); // https.createServer(httpsOption, app).listen(3000, function(){
}); // console.log('https listening on *:3000');
\ No newline at end of file // });
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment