Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
764aa164
Unverified
Commit
764aa164
authored
Oct 09, 2018
by
Robert Knight
Committed by
GitHub
Oct 09, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #785 from hypothesis/support-ssl-in-dev
Support serving the client over SSL in development
parents
2f3e6922
1ba23cce
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
8 deletions
+62
-8
.gitignore
.gitignore
+4
-0
gulpfile.js
gulpfile.js
+5
-2
create-server.js
scripts/gulp/create-server.js
+42
-0
live-reload-server.js
scripts/gulp/live-reload-server.js
+7
-4
serve-package.js
scripts/gulp/serve-package.js
+4
-2
No files found.
.gitignore
View file @
764aa164
...
...
@@ -5,3 +5,7 @@ docs/_build/
# The client uses Yarn rather than npm to manage the lockfile.
package-lock.json
# SSL certificate and key.
.tlscert.pem
.tlskey.pem
gulpfile.js
View file @
764aa164
...
...
@@ -24,6 +24,7 @@ const createBundle = require('./scripts/gulp/create-bundle');
const
manifest
=
require
(
'./scripts/gulp/manifest'
);
const
servePackage
=
require
(
'./scripts/gulp/serve-package'
);
const
vendorBundles
=
require
(
'./scripts/gulp/vendor-bundles'
);
const
{
useSsl
}
=
require
(
'./scripts/gulp/create-server'
);
const
IS_PRODUCTION_BUILD
=
process
.
env
.
NODE_ENV
===
'production'
;
const
SCRIPT_DIR
=
'build/scripts'
;
...
...
@@ -272,7 +273,8 @@ function generateBootScript(manifest) {
if
(
process
.
env
.
NODE_ENV
===
'production'
)
{
defaultAssetRoot
=
`https://cdn.hypothes.is/hypothesis/
${
version
}
/`
;
}
else
{
defaultAssetRoot
=
`http://
${
packageServerHostname
()}
:3001/hypothesis/
${
version
}
/`
;
const
scheme
=
useSsl
?
'https'
:
'http'
;
defaultAssetRoot
=
`
${
scheme
}
://
${
packageServerHostname
()}
:3001/hypothesis/
${
version
}
/`
;
}
if
(
isFirstBuild
)
{
...
...
@@ -325,8 +327,9 @@ gulp.task('watch-manifest', function () {
gulp
.
task
(
'serve-live-reload'
,
[
'serve-package'
],
function
()
{
const
LiveReloadServer
=
require
(
'./scripts/gulp/live-reload-server'
);
const
scheme
=
useSsl
?
'https'
:
'http'
;
liveReloadServer
=
new
LiveReloadServer
(
3000
,
{
clientUrl
:
`
http
://
${
packageServerHostname
()}
:3001/hypothesis`
,
clientUrl
:
`
${
scheme
}
://
${
packageServerHostname
()}
:3001/hypothesis`
,
});
});
...
...
scripts/gulp/create-server.js
0 → 100644
View file @
764aa164
'use strict'
;
const
{
existsSync
,
readFileSync
}
=
require
(
'fs'
);
const
https
=
require
(
'https'
);
const
http
=
require
(
'http'
);
const
SSL_KEYFILE
=
'.tlskey.pem'
;
const
SSL_CERTFILE
=
'.tlscert.pem'
;
/**
* `true` if dev servers created using `createServer` use SSL.
*
* @type {boolean}
*/
const
useSsl
=
existsSync
(
SSL_KEYFILE
)
&&
existsSync
(
SSL_CERTFILE
);
/**
* Create an HTTP(S) server to serve client assets in development.
*
* Uses SSL if ".tlskey.pem" and ".tlscert.pem" files exist in the root of
* the repository or plain HTTP otherwise.
*
* @param {Function} requestListener
*/
function
createServer
(
requestListener
)
{
let
server
;
if
(
useSsl
)
{
const
options
=
{
cert
:
readFileSync
(
SSL_CERTFILE
),
key
:
readFileSync
(
SSL_KEYFILE
),
};
server
=
https
.
createServer
(
options
,
requestListener
);
}
else
{
server
=
http
.
createServer
(
requestListener
);
}
return
server
;
}
module
.
exports
=
{
createServer
,
useSsl
,
};
scripts/gulp/live-reload-server.js
View file @
764aa164
...
...
@@ -2,10 +2,11 @@
const
fs
=
require
(
'fs'
);
const
gulpUtil
=
require
(
'gulp-util'
);
const
http
=
require
(
'http'
);
const
WebSocketServer
=
require
(
'websocket'
).
server
;
const
urlParser
=
require
(
'url'
);
const
{
createServer
,
useSsl
}
=
require
(
'./create-server'
);
function
readmeText
()
{
return
fs
.
readFileSync
(
'./README.md'
,
'utf-8'
);
}
...
...
@@ -41,7 +42,7 @@ function LiveReloadServer(port, config) {
function
listen
()
{
const
log
=
gulpUtil
.
log
;
const
server
=
http
.
createServer
(
function
(
req
,
response
)
{
const
app
=
function
(
req
,
response
)
{
const
url
=
urlParser
.
parse
(
req
.
url
);
let
content
;
...
...
@@ -136,13 +137,15 @@ function LiveReloadServer(port, config) {
`
;
}
response
.
end
(
content
);
}
)
;
};
const
server
=
createServer
(
app
);
server
.
listen
(
port
,
function
(
err
)
{
if
(
err
)
{
log
(
'Setting up live reload server failed'
,
err
);
}
log
(
`Live reload server listening at http://localhost:
${
port
}
/`
);
const
scheme
=
useSsl
?
'https'
:
'http'
;
log
(
`Live reload server listening at
${
scheme
}
://localhost:
${
port
}
/`
);
});
const
ws
=
new
WebSocketServer
({
...
...
scripts/gulp/serve-package.js
View file @
764aa164
...
...
@@ -5,6 +5,7 @@ const { readFileSync } = require('fs');
const
express
=
require
(
'express'
);
const
{
log
}
=
require
(
'gulp-util'
);
const
{
createServer
,
useSsl
}
=
require
(
'./create-server'
);
const
{
version
}
=
require
(
'../../package.json'
);
/**
...
...
@@ -40,8 +41,9 @@ function servePackage(port, hostname) {
app
.
get
(
`/hypothesis/
${
version
}
`
,
serveBootScript
);
app
.
use
(
`/hypothesis/
${
version
}
/`
,
express
.
static
(
'.'
));
app
.
listen
(
port
,
function
()
{
log
(
`Package served at http://
${
hostname
}
:
${
port
}
/hypothesis`
);
createServer
(
app
).
listen
(
port
,
()
=>
{
const
scheme
=
useSsl
?
'https'
:
'http'
;
log
(
`Package served at
${
scheme
}
://
${
hostname
}
:
${
port
}
/hypothesis`
);
});
}
...
...
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