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
dc08b1e6
Commit
dc08b1e6
authored
Aug 14, 2019
by
何硕
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'heshuo' into 'master'
Heshuo See merge request
!7
parents
635457a9
9c5b5899
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
16 deletions
+13
-16
index.js
index.js
+13
-16
No files found.
index.js
View file @
dc08b1e6
var
app
=
require
(
'
express
'
)();
var
app
=
require
(
'
express
'
)();
var
http
=
require
(
'
http
'
).
createServer
(
app
);
var
http
=
require
(
'
http
'
).
createServer
(
app
);
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
"
);
//跨域CORS设置
app
.
use
((
req
,
res
,
next
)
=>
{
res
.
header
(
"
Access-Control-Allow-Origin
"
,
"
*
"
);
res
.
header
(
"
Access-Control-Allow-Methods
"
,
"
*
"
);
res
.
header
(
"
Access-Control-Allow-Credentials
"
,
"
true
"
);
res
.
header
(
"
Access-Control-Allow-Headers
"
,
"
Content-Type,Access-Token,adminid
"
);
res
.
header
(
"
Access-Control-Expose-Headers
"
,
"
*
"
);
if
(
req
.
method
==
'
OPTIONS
'
)
{
res
.
send
(
200
);
/*让options请求快速返回*/
}
else
{
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
=
{
key
:
fs
.
readFileSync
(
"
/etc/letsencrypt/live/livesocket.xueyoubangedu.com/privkey.pem
"
),
cert
:
fs
.
readFileSync
(
"
/etc/letsencrypt/live/livesocket.xueyoubangedu.com/fullchain.pem
"
)
}
app
.
get
(
'
/
'
,
function
(
req
,
res
){
app
.
get
(
'
/
'
,
function
(
req
,
res
){
res
.
send
(
'
<h1>Hello world</h1>
'
);
res
.
send
(
'
<h1>Hello world</h1>
'
);
});
});
...
@@ -104,7 +98,10 @@ io.on('connection', function(socket){
...
@@ -104,7 +98,10 @@ io.on('connection', function(socket){
});
});
// http.listen(3000, function(){
// console.log('http listening on *:3000');
// });
http
.
listen
(
3000
,
function
(){
http
s
.
createServer
(
httpsOption
,
app
)
.
listen
(
3000
,
function
(){
console
.
log
(
'
listening on *:3000
'
);
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