@merkur/cli 0.41.0 → 0.41.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/devServer.mjs +31 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@merkur/cli",
3
- "version": "0.41.0",
3
+ "version": "0.41.1",
4
4
  "description": "Merkur is tiny and extensible library for creating front-end microservices.",
5
5
  "bin": {
6
6
  "merkur": "./bin/merkur.mjs"
@@ -64,5 +64,5 @@
64
64
  "engines": {
65
65
  "node": ">=20"
66
66
  },
67
- "gitHead": "dc4b714d1a572843c3a8f9a4c4895891d182edef"
67
+ "gitHead": "6f84047abdcb3731f35377790cdafe9e7d491c40"
68
68
  }
package/src/devServer.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import path from 'node:path';
2
2
  import fs from 'node:fs';
3
+ import https from 'node:https';
3
4
  import ejs from 'ejs';
4
5
  import chalk from 'chalk';
5
6
 
@@ -21,8 +22,16 @@ function asyncMiddleware(fn) {
21
22
 
22
23
  export async function runDevServer({ context, merkurConfig, cliConfig }) {
23
24
  const logger = createLogger('devServer', cliConfig);
24
- const { protocol, host, port, staticPath, staticFolder, origin } =
25
- merkurConfig.devServer;
25
+ const {
26
+ protocol,
27
+ host,
28
+ port,
29
+ staticPath,
30
+ staticFolder,
31
+ origin,
32
+ httpsKey,
33
+ httpsCert,
34
+ } = merkurConfig.devServer;
26
35
  const {
27
36
  template,
28
37
  templateFolder,
@@ -36,7 +45,7 @@ export async function runDevServer({ context, merkurConfig, cliConfig }) {
36
45
  return new Promise((resolve, reject) => {
37
46
  const app = express();
38
47
 
39
- const server = app
48
+ app
40
49
  .use((req, res, next) => {
41
50
  const headerOrigin = req.get('Origin');
42
51
  // Allow cors
@@ -204,15 +213,28 @@ export async function runDevServer({ context, merkurConfig, cliConfig }) {
204
213
  stack: error.stack,
205
214
  },
206
215
  });
207
- })
208
- .listen({ port }, () => {
209
- logger.info(`Playground: ${chalk.green(`${protocol}//${host}`)}`);
210
- resolve(app);
211
216
  });
212
217
 
213
- context.server.devServer = server;
218
+ // Create HTTPS server if protocol is https:
219
+ let server;
220
+ if (protocol === 'https:') {
221
+ const httpsOptions = {
222
+ key: httpsKey,
223
+ cert: httpsCert,
224
+ };
225
+ server = https.createServer(httpsOptions, app);
226
+ } else {
227
+ server = app;
228
+ }
229
+
230
+ const httpServer = server.listen({ port }, () => {
231
+ logger.info(`Playground: ${chalk.green(`${protocol}//${host}`)}`);
232
+ resolve(app);
233
+ });
234
+
235
+ context.server.devServer = httpServer;
214
236
 
215
- server.on('error', (error) => {
237
+ httpServer.on('error', (error) => {
216
238
  reject(error);
217
239
  });
218
240
  });