@nitro/app 11.0.4 → 11.0.6

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.
@@ -39,6 +39,7 @@ const defaultConfig = {
39
39
  },
40
40
  server: {
41
41
  port: 8080,
42
+ hmrPort: 3000,
42
43
  host: 'localhost',
43
44
  production: !!(process.env.NODE_ENV && process.env.NODE_ENV.replace(/\s/g, '') === 'production'),
44
45
  compression: true,
@@ -1,14 +1,15 @@
1
1
  'use strict';
2
2
 
3
3
  const config = require('config');
4
+ const utils = require('./utils');
5
+
4
6
  const mode = config.get('server.production') ? 'production' : 'development';
5
7
  const port = config.get('server.port');
8
+ const hmrPort = config.get('server.hmrPort');
6
9
 
7
10
  /* eslint-disable no-console */
8
- module.exports = function (app, opts = {}) {
9
- const rawHost = (config.has('server.host')) ? config.get('server.host') : 'localhost';
10
- const host = ['0.0.0.0', '::', '::0'].includes(String(rawHost)) ? 'localhost' : rawHost;
11
- const url = `http://${host}:${port}`;
11
+ module.exports = function (app, hmrApp, opts = {}) {
12
+ const url = utils.getServerBaseUrl(port);
12
13
  const openBrowser = opts.open; // true | false | string (URL)
13
14
 
14
15
  const server = app
@@ -37,6 +38,19 @@ module.exports = function (app, opts = {}) {
37
38
  process.exit(1);
38
39
  });
39
40
 
41
+ if (hmrApp && mode === 'development') {
42
+ hmrApp
43
+ .listen(hmrPort)
44
+ .on('error', (err) => {
45
+ if (err && err.errno === 'EADDRINUSE') {
46
+ console.error('Proxy Port *:%s already in use.', hmrPort);
47
+ } else {
48
+ console.error(err);
49
+ }
50
+ process.exit(1);
51
+ });
52
+ }
53
+
40
54
  return server;
41
55
  };
42
56
  /* eslint-enable no-console */
package/app/core/utils.js CHANGED
@@ -4,6 +4,13 @@ const fs = require('fs');
4
4
  const path = require('path');
5
5
  const config = require('config');
6
6
 
7
+ function getServerBaseUrl(port) {
8
+ port = port || config.get('server.port');
9
+ const rawHost = (config.has('server.host')) ? config.get('server.host') : 'localhost';
10
+ const host = ['0.0.0.0', '::', '::0'].includes(String(rawHost)) ? 'localhost' : rawHost;
11
+ return `http://${host}:${port}`;
12
+ }
13
+
7
14
  function getLayoutName(layoutPath) {
8
15
  const layoutPathWithoutViewPath = config
9
16
  .get('nitro.viewLayoutsDirectory')
@@ -27,6 +34,7 @@ function layoutExists(layoutName) {
27
34
  }
28
35
 
29
36
  module.exports = {
37
+ getServerBaseUrl,
30
38
  getLayoutName,
31
39
  getLayoutPath,
32
40
  layoutExists,
@@ -5,6 +5,9 @@ const webpack = require('webpack');
5
5
  const webpackMiddleware = require('webpack-dev-middleware');
6
6
  const webpackHotMiddleware = require('webpack-hot-middleware');
7
7
  const config = require('config');
8
+ const utils = require('./utils');
9
+
10
+ const url = utils.getServerBaseUrl();
8
11
  const webpackConfig = require(process.env.WEBPACK_CONFIG
9
12
  ? path.join(config.get('nitro.basePath'), process.env.WEBPACK_CONFIG)
10
13
  : path.normalize(path.join(config.get('nitro.basePath'), 'config', 'webpack', 'webpack.config.dev')));
@@ -18,9 +21,13 @@ const wphm = webpackHotMiddleware(webpackCompiler, {
18
21
  heartbeat: 10 * 1000,
19
22
  });
20
23
 
21
- module.exports = function (app) {
24
+ module.exports = function (app, hmrApp) {
22
25
  app.use(wpm);
23
- if (config.get('nitro.mode.livereload')) {
24
- app.use(wphm);
26
+ if (hmrApp && config.get('nitro.mode.livereload')) {
27
+ hmrApp.use((req, res, next) => {
28
+ res.setHeader('Access-Control-Allow-Origin', url);
29
+ next();
30
+ });
31
+ hmrApp.use(wphm);
25
32
  }
26
33
  };
@@ -15,11 +15,13 @@ const isProduction = config.get('server.production');
15
15
  const useCompression = config.get('server.compression');
16
16
  const isTwig = config.get('nitro.templateEngine') === 'twig';
17
17
 
18
+ let hmrApp;
18
19
  let engine;
19
20
 
20
21
  // webpack
21
22
  if (!isProduction) {
22
- require('../core/webpack')(app);
23
+ hmrApp = express();
24
+ require('../core/webpack')(app, hmrApp);
23
25
  }
24
26
 
25
27
  if (isTwig) {
@@ -52,4 +54,4 @@ if (isTwig) {
52
54
  app.engine(config.get('nitro.viewFileExtension'), engine.__express);
53
55
  }
54
56
 
55
- require('../core/listen')(app, { open });
57
+ require('../core/listen')(app, hmrApp, { open });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitro/app",
3
- "version": "11.0.4",
3
+ "version": "11.0.6",
4
4
  "description": "Nitro server",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -45,7 +45,7 @@
45
45
  "hbs": "4.2.0",
46
46
  "hbs-utils": "0.0.4",
47
47
  "html-validate": "7.18.1",
48
- "i18next": "25.8.13",
48
+ "i18next": "25.8.14",
49
49
  "i18next-http-middleware": "3.9.2",
50
50
  "i18next-fs-backend": "2.6.1",
51
51
  "i18next-sprintf-postprocessor": "0.2.2",
@@ -63,7 +63,7 @@
63
63
  "@merkle-open/eslint-config": "4.0.1",
64
64
  "eslint": "8.57.1",
65
65
  "eslint-plugin-import": "2.32.0",
66
- "webpack": "5.105.3"
66
+ "webpack": "5.105.4"
67
67
  },
68
68
  "publishConfig": {
69
69
  "access": "public"