Skip to content

Commit cd8219e

Browse files
committed
First pass at https option for devServer
1 parent 229ddea commit cd8219e

File tree

4 files changed

+70
-2
lines changed

4 files changed

+70
-2
lines changed

bin/hjs-dev-server.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Based on
44
// https://github.com/gaearon/react-transform-boilerplate/blob/master/devServer.js
55

6+
var fs = require('fs')
67
var path = require('path')
78
var express = require('express')
89
var webpack = require('webpack')
@@ -21,7 +22,21 @@ try {
2122
}
2223

2324
var serverConfig = config.devServer
25+
var https = serverConfig.https
2426
var app = express()
27+
28+
var createServer = require(https ? 'https' : 'http').createServer
29+
var server
30+
31+
if (https) {
32+
server = createServer({
33+
key: fs.readFileSync(path.resolve(__dirname, '../resources/hjs-webpack-localhost.key')),
34+
cert: fs.readFileSync(path.resolve(__dirname, '../resources/hjs-webpack-localhost.crt'))
35+
}, app)
36+
} else {
37+
server = createServer(app)
38+
}
39+
2540
var compiler = webpack(config)
2641

2742
if (serverConfig.historyApiFallback) {
@@ -40,11 +55,12 @@ if (serverConfig.contentBase) {
4055
app.use(express.static(serverConfig.contentBase))
4156
}
4257

43-
app.listen(serverConfig.port, serverConfig.hostname, function (err) {
58+
server.listen(serverConfig.port, serverConfig.hostname, function (err) {
4459
if (err) {
4560
console.error(err)
4661
return
4762
}
4863

49-
console.log('Listening at http://' + serverConfig.hostname + ':' + serverConfig.port)
64+
var protocol = https ? 'https' : 'http'
65+
console.log('Listening at ' + protocol + '://' + serverConfig.hostname + ':' + serverConfig.port)
5066
})

index.js

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = function (opts) {
3131
isDev: isDev,
3232
package: null,
3333
replace: null,
34+
https: false,
3435
port: 3000,
3536
hostname: 'localhost',
3637
html: true,
@@ -93,6 +94,7 @@ module.exports = function (opts) {
9394
hot: true,
9495
contentBase: outputFolder,
9596
port: spec.port,
97+
https: spec.https,
9698
hostname: spec.hostname || spec.host
9799
})
98100

resources/hjs-webpack-localhost.crt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIID1DCCArwCCQC1ATCF3SR0PzANBgkqhkiG9w0BAQUFADCBqzELMAkGA1UEBhMC
3+
VVMxEzARBgNVBAgTCldhc2hpbmd0b24xEzARBgNVBAcTClRyaS1DaXRpZXMxIDAe
4+
BgNVBAoTF0hKUy1XZWJwYWNrIC8gQnJpZWZjYXNlMRowGAYDVQQLExFMb3ZlbHkg
5+
RGV2IFNlcnZlcjESMBAGA1UEAxMJbG9jYWxob3N0MSAwHgYJKoZIhvcNAQkBFhF0
6+
ZGRAdGRkc3dvcmxkLmNvbTAeFw0xNjAyMDUyMjQwMzBaFw0xNzAyMDQyMjQwMzBa
7+
MIGrMQswCQYDVQQGEwJVUzETMBEGA1UECBMKV2FzaGluZ3RvbjETMBEGA1UEBxMK
8+
VHJpLUNpdGllczEgMB4GA1UEChMXSEpTLVdlYnBhY2sgLyBCcmllZmNhc2UxGjAY
9+
BgNVBAsTEUxvdmVseSBEZXYgU2VydmVyMRIwEAYDVQQDEwlsb2NhbGhvc3QxIDAe
10+
BgkqhkiG9w0BCQEWEXRkZEB0ZGRzd29ybGQuY29tMIIBIjANBgkqhkiG9w0BAQEF
11+
AAOCAQ8AMIIBCgKCAQEA6mp5nenSuBTwVJoRvkeJwcBDAXAeWD8HNbrBGRcCfrgE
12+
HD9b7VgqUkGjYJR7CpE/B3j76pMA9QZgLrsnqYQykUPgfzEeKX6iHacKzadQTiqY
13+
0nHX3rRafQ7Okv+qMk8YxKOBcsXIWMErGBK3BbRHlH+lKLH2O/EAorcRoBvUrZke
14+
BaoOOObySXwCcwr39G1V490BPEklz5H2pH15ibOaqAPo8u7f5vR8bMxpfqMCbW1l
15+
1kbKO3RpayZ7G8evyJ/jgg3ZxY3QmCSFzE0u9khuTRRH29hfcLQ8Wt7gh2A1SkhH
16+
wz/d2f7uGzF/Ryd/4gSpr8BZNm05O7SzRKsfYTuAwQIDAQABMA0GCSqGSIb3DQEB
17+
BQUAA4IBAQCoKJddSANdqFxgon+97ga9jS9TRUAzOuJDnHIxJTUzk4Gt9M9hrF6M
18+
h2i6cwjq6wdJeTE8mAHnGIxzZC3HpmpDatNzj81bXKPLvoKbCRnYPng7vOKwxzvz
19+
uWBfryrXZ1yb43yUpLmTqHmaeNwO3dzxXYljD2Zb2Dq0MsEcCdeA7rGtlCeJ8EiX
20+
x4eclRXGve8TGUbMV2trFOf95lo9ktsZ+7MGi0Eo469ZaefKuo6kLdHTe+qnp5cr
21+
8eOyE2H64i94vZiIrd3LFSLa7uJFybxlHYidkHBVP7DQ/TgZYiCljK3t8nU2IAsx
22+
OSVR0lFQQ7D1DtcPmjgpYC0iPP5p5IcM
23+
-----END CERTIFICATE-----

resources/hjs-webpack-localhost.key

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIIEpQIBAAKCAQEA6mp5nenSuBTwVJoRvkeJwcBDAXAeWD8HNbrBGRcCfrgEHD9b
3+
7VgqUkGjYJR7CpE/B3j76pMA9QZgLrsnqYQykUPgfzEeKX6iHacKzadQTiqY0nHX
4+
3rRafQ7Okv+qMk8YxKOBcsXIWMErGBK3BbRHlH+lKLH2O/EAorcRoBvUrZkeBaoO
5+
OObySXwCcwr39G1V490BPEklz5H2pH15ibOaqAPo8u7f5vR8bMxpfqMCbW1l1kbK
6+
O3RpayZ7G8evyJ/jgg3ZxY3QmCSFzE0u9khuTRRH29hfcLQ8Wt7gh2A1SkhHwz/d
7+
2f7uGzF/Ryd/4gSpr8BZNm05O7SzRKsfYTuAwQIDAQABAoIBAQDCuipG5Jr38eTm
8+
0omUwEaOHZFL24BJnCn4FygbGIMpEuHPOU667fdSF1aJfy5qy9dI9NaHuRAdeuth
9+
RnUfG0MKaxFNd1bv71LqQP33clqCZF5IyushBD77DdbKQ/l1C0Gu74gz+FqCaAzN
10+
VZaV9XlUwWhIUvUSPB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