Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPS fixes #133

Merged
merged 2 commits into from
Aug 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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