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')();
var http = require('http').createServer(app);
var https = require("https");
var axios = require('axios');
var io = require('socket.io')(http);
// var io = require('socket.io')(http);
let fs = require("fs");
......@@ -15,33 +15,39 @@ let fs = require("fs");
// next();
// });
//allow custom header and CORS
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-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
// 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-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
// res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
if (req.method == 'OPTIONS') {
res.send(200);
}
else {
next();
}
});
// if (req.method == 'OPTIONS') {
// res.send(200);
// }
// else {
// next();
// }
// });
// var BaseUrl = "http://localhost/api/";
var BaseUrl = "https://zhibo.xueyoubangedu.com/api/";
// var BaseUrl = "https://live.xueyoubangedu.com/api/";
const httpsOption = {
key : fs.readFileSync("./https/privkey.pem"),
cert: fs.readFileSync("./https/fullchain.pem")
}
// const httpsOption = {
// key : fs.readFileSync("./https/privkey.pem"),
// cert: fs.readFileSync("./https/fullchain.pem")
// }
app.get('/', function(req, res){
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){
console.log("connection");
//监听用户登录
......@@ -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');
});
\ No newline at end of file
// https.createServer(httpsOption, app).listen(3000, function(){
// console.log('https listening on *:3000');
// });
\ 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