Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liveserver
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
何硕
liveserver
Commits
81c0bad3
Commit
81c0bad3
authored
Aug 15, 2019
by
何硕
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test wss
parent
dbb9e683
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
22 deletions
+26
-22
index.js
index.js
+26
-22
No files found.
index.js
View file @
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment