Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wiki-js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
wiki-js
Commits
abe5f3b2
Commit
abe5f3b2
authored
Feb 24, 2019
by
Nick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: HTTP redirect to HTTPS server option
parent
21413663
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
1 deletion
+43
-1
config.sample.yml
config.sample.yml
+4
-0
master.js
server/master.js
+39
-1
No files found.
config.sample.yml
View file @
abe5f3b2
...
@@ -66,6 +66,10 @@ ssl:
...
@@ -66,6 +66,10 @@ ssl:
# to 1024 bits (default: null):
# to 1024 bits (default: null):
dhparam
:
null
dhparam
:
null
# Listen on this HTTP port and redirect all requests to HTTPS.
# Set to false to disable (default: 80):
redirectNonSSLPort
:
80
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# IP address the server should listen to
# IP address the server should listen to
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
...
...
server/master.js
View file @
abe5f3b2
...
@@ -165,7 +165,7 @@ module.exports = async () => {
...
@@ -165,7 +165,7 @@ module.exports = async () => {
})
})
// ----------------------------------------
// ----------------------------------------
// HTTP server
// HTTP
/S
server
// ----------------------------------------
// ----------------------------------------
let
srvConnections
=
{}
let
srvConnections
=
{}
...
@@ -193,6 +193,14 @@ module.exports = async () => {
...
@@ -193,6 +193,14 @@ module.exports = async () => {
return
process
.
exit
(
1
)
return
process
.
exit
(
1
)
}
}
WIKI
.
server
=
https
.
createServer
(
tlsOpts
,
app
)
WIKI
.
server
=
https
.
createServer
(
tlsOpts
,
app
)
// HTTP Redirect Server
if
(
WIKI
.
config
.
ssl
.
redirectNonSSLPort
)
{
WIKI
.
serverAlt
=
http
.
createServer
((
req
,
res
)
=>
{
res
.
writeHead
(
301
,
{
'Location'
:
'https://'
+
req
.
headers
[
'host'
]
+
req
.
url
})
res
.
end
()
})
}
}
else
{
}
else
{
WIKI
.
logger
.
info
(
`HTTP Server on port: [
${
WIKI
.
config
.
port
}
]`
)
WIKI
.
logger
.
info
(
`HTTP Server on port: [
${
WIKI
.
config
.
port
}
]`
)
WIKI
.
server
=
http
.
createServer
(
app
)
WIKI
.
server
=
http
.
createServer
(
app
)
...
@@ -229,6 +237,32 @@ module.exports = async () => {
...
@@ -229,6 +237,32 @@ module.exports = async () => {
WIKI
.
server
.
on
(
'listening'
,
()
=>
{
WIKI
.
server
.
on
(
'listening'
,
()
=>
{
if
(
WIKI
.
config
.
ssl
.
enabled
)
{
if
(
WIKI
.
config
.
ssl
.
enabled
)
{
WIKI
.
logger
.
info
(
'HTTPS Server: [ RUNNING ]'
)
WIKI
.
logger
.
info
(
'HTTPS Server: [ RUNNING ]'
)
// Start HTTP Redirect Server
if
(
WIKI
.
config
.
ssl
.
redirectNonSSLPort
)
{
WIKI
.
serverAlt
.
listen
(
WIKI
.
config
.
ssl
.
redirectNonSSLPort
,
WIKI
.
config
.
bindIP
)
WIKI
.
serverAlt
.
on
(
'error'
,
(
error
)
=>
{
if
(
error
.
syscall
!==
'listen'
)
{
throw
error
}
switch
(
error
.
code
)
{
case
'EACCES'
:
WIKI
.
logger
.
error
(
'(HTTP Redirect) Listening on port '
+
WIKI
.
config
.
port
+
' requires elevated privileges!'
)
return
process
.
exit
(
1
)
case
'EADDRINUSE'
:
WIKI
.
logger
.
error
(
'(HTTP Redirect) Port '
+
WIKI
.
config
.
port
+
' is already in use!'
)
return
process
.
exit
(
1
)
default
:
throw
error
}
})
WIKI
.
serverAlt
.
on
(
'listening'
,
()
=>
{
WIKI
.
logger
.
info
(
'HTTP Server: [ RUNNING in redirect mode ]'
)
})
}
}
else
{
}
else
{
WIKI
.
logger
.
info
(
'HTTP Server: [ RUNNING ]'
)
WIKI
.
logger
.
info
(
'HTTP Server: [ RUNNING ]'
)
}
}
...
@@ -239,6 +273,10 @@ module.exports = async () => {
...
@@ -239,6 +273,10 @@ module.exports = async () => {
for
(
let
key
in
srvConnections
)
{
for
(
let
key
in
srvConnections
)
{
srvConnections
[
key
].
destroy
()
srvConnections
[
key
].
destroy
()
}
}
if
(
WIKI
.
config
.
ssl
.
enabled
&&
WIKI
.
config
.
ssl
.
redirectNonSSLPort
)
{
WIKI
.
serverAlt
.
close
(
cb
)
}
}
}
return
true
return
true
...
...
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