Skip to content

Commit

Permalink
Merge pull request #133 from Filyus/master
Browse files Browse the repository at this point in the history
HTTPS fixes
  • Loading branch information
PepsRyuu authored Aug 15, 2020
2 parents 99a3283 + c6a997c commit ac0b241
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/dev-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ let mime = require('mime-types');
let path = require('path');
let { createFilter } = require('@rollup/pluginutils');

module.exports = function (app, config, options) {
expressws(app);
module.exports = function (app, config, options, server) {
expressws(app, server);
let bundles = [];
let isBundling = true;
let files = {};
Expand Down
26 changes: 14 additions & 12 deletions lib/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ async function devServer(options) {
options.before(app);
}

let server
if (options.https) {
if (!(options.key && options.cert)) {
throw new Error('Usage of https requires cert and key to be set.')
}
const key = fs.readFileSync(options.key)
const cert = fs.readFileSync(options.cert)
server = https.createServer({ key, cert }, app)
} else {
server = http.createServer(app)
}

if (options.headers) {
app.all('*', (req, res, next) => {
for (let prop in options.headers) {
Expand All @@ -38,7 +50,7 @@ async function devServer(options) {
hmrHost: options.hmrHost,
contentBase: options.contentBase,
publicPath: options.publicPath
}));
}, server));

if (options.proxy) {
Object.keys(options.proxy).forEach(route => {
Expand All @@ -63,17 +75,7 @@ async function devServer(options) {
app.use(fallback(entryPoint, { root: options.contentBase }));
}

if (options.https) {
if (!(options.key && options.cert)) {
throw new Error('Usage of https requires cert and key to be set.');
}

const key = fs.readFileSync(options.key);
const cert = fs.readFileSync(options.cert);
https.createServer({ key, cert }, app).listen(options.port);
} else {
app.listen(options.port);
}
server.listen(options.port);

console.log(`[Nollup] Listening on ${options.https ? 'https' : 'http'}://localhost:${options.port}`);
}
Expand Down

0 comments on commit ac0b241

Please sign in to comment.