question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. Itย collects links to all the places you might be looking at while hunting down a tough bug.

And, if youโ€™re still stuck at the end, weโ€™re happy to hop on a call to see how we can help out.

Serve for the client uses a hardcoded port

See original GitHub issue

The client port is hardcoded which makes it not possible to provide an alternative port via the package.json.

Steps to reproduce the behavior:

$ mevn init test
$ cd test
# set a port in package.json for the dev script
$ sed -i 's/dev": "nuxt/dev": "nuxt --port 8080/' client/package.json
$ mevn serve
  __  __ _______     ___   _    ____ _     ___
 |  \/  | ____\ \   / / \ | |  / ___| |   |_ _|
 | |\/| |  _|  \ \ / /|  \| | | |   | |    | |
 | |  | | |___  \ V / | |\  | | |___| |___ | |
 |_|  |_|_____|  \_/  |_| \_|  \____|_____|___|

 Light speed setup for MEVN stack based apps.
? Choose from below client

> nuxt@1.0.0 dev
> nuxt --port 8080 "--port" "3000" "--open"

 WARN  mode option is deprecated. You can safely remove it from nuxt.config                                                                                                                                                         06:05:57

 FATAL  options.port should be >= 0 and < 65536. Received NaN.

Expected behavior:

to be able to specify port and host in the package.json for scripts

$ cd client/
$ npm run dev

> nuxt@1.0.0 dev
> nuxt -H 0.0.0.0 --port 8080

...
โ„น Waiting for file changes                                                                                                                                                                                                          06:21:30
โ„น Memory usage: 200 MB (RSS: 286 MB)                                                                                                                                                                                                06:21:30
โ„น Listening on: http://172.16.16.16:8080/

Modified /usr/lib/node_modules/mevn-cli/lib/commands/serve/launch.js From:

 61             _execa["default"].command("npm run ".concat(cmd, " -- --port ").concat(port, " --open"), {

To:

 61             _execa["default"].command("npm run ".concat(cmd, " --  --open"), {

Now it works as expected:

$ mevn serve
  __  __ _______     ___   _    ____ _     ___
 |  \/  | ____\ \   / / \ | |  / ___| |   |_ _|
 | |\/| |  _|  \ \ / /|  \| | | |   | |    | |
 | |  | | |___  \ V / | |\  | | |___| |___ | |
 |_|  |_|_____|  \_/  |_| \_|  \____|_____|___|

 Light speed setup for MEVN stack based apps.
? Choose from below client

> nuxt@1.0.0 dev
> nuxt -H 0.0.0.0 --port 8080 "--open"


 WARN  mode option is deprecated. You can safely remove it from nuxt.config
 
   โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
   โ”‚                                          โ”‚
   โ”‚   Nuxt @ v2.15.4                         โ”‚
   โ”‚                                          โ”‚
   โ”‚   โ–ธ Environment: development             โ”‚
   โ”‚   โ–ธ Rendering:   server-side             โ”‚
   โ”‚   โ–ธ Target:      server                  โ”‚
   โ”‚                                          โ”‚
   โ”‚   Listening: http://172.16.16.16:8080/   โ”‚
   โ”‚                                          โ”‚
   โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

โ„น Preparing project for development                                                                                                                                                                                                 06:12:06
โ„น Initial build may take a while                                                                                                                                                                                                    06:12:06
โ„น Discovered Components: .nuxt/components/readme.md                                                                                                                                                                                 06:12:06
โœ” Builder initialized                                                                                                                                                                                                               06:12:06
โœ” Nuxt files generated                                                                                                                                                                                                              06:12:06

โœ” Client
  Compiled successfully in 2.63s

โœ” Server
  Compiled successfully in 1.58s

โ„น Waiting for file changes                                                                                                                                                                                                          06:12:09
โ„น Memory usage: 205 MB (RSS: 295 MB)                                                                                                                                                                                                06:12:09
โ„น Listening on: http://172.16.16.16:8080/

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
jamesgeorge007commented, May 10, 2021

Iโ€™d suggest making the following changes in src/commands/serve/launch.js

diff --git a/src/commands/serve/launch.js b/src/commands/serve/launch.js
index 1bb36b4..0e3940d 100644
--- a/src/commands/serve/launch.js
+++ b/src/commands/serve/launch.js
@@ -14,15 +14,8 @@ import exec from '../../utils/exec';
  */

 export default async (projectConfig, templateDir) => {
-  let port;
   const { template: projectTemplate, isConfigured } = projectConfig;

-  if (templateDir === 'client') {
-    port = projectTemplate === 'Nuxt.js' ? '3000' : '3002';
-  } else {
-    port = projectTemplate === 'GraphQL' ? '9000/graphql' : '9000/api';
-  }
-
   if (!isConfigured[templateDir]) {
     await exec(
       'npm install',
@@ -39,7 +32,8 @@ export default async (projectConfig, templateDir) => {
   }

   const cmd = projectTemplate === 'Nuxt.js' ? 'dev' : 'serve';
-  execa.command(`npm run ${cmd} -- --port ${port} --open`, {
+  const options = templateDir === 'client' ? ' -- --open' : '';
+  await execa.command(`npm run ${cmd}${options}`, {
     stdio: 'inherit',
     cwd: templateDir,
   });
0reactions
koapscommented, May 10, 2021

might want to do the same for the server.

itโ€™s a bit easier to override since I could edit server.js or the port env var, but probably better to allow it to be set in package.json.

I was able to override it to port 8008 but the server startup message still says its going to uae 9000.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why port 80 is used for server applications? - Stack Overflow
Server port number has to be hard coded in server and client application? Yes, that is one way to do it. Server port...
Read more >
Why not hard-code the port number for an application that will ...
Suppose I am creating an Express app that will be dockerized. What's wrong with making it listen to a hard-coded port, e.g. 8080:...
Read more >
What hard coded ports are used by CONTROL-M products, for ...
- Database ports. Sybase: Defaults are 7102 and 7103. One port is used by the dataserver processes and one by the backupserver processes.ย ......
Read more >
Explicitly assigning port number to client in Socket
So, it is highly probable that the port number provided to the client by the operating system may have been blocked by the...
Read more >
force program hardcoded to listen on a port to use another port?
You have a client program on machine A that makes HTTP requests to machine B on port 80. And you have a server...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found