Open koaps opened 3 years ago
Thanks for opening your first issue here! Be sure to follow the issue template!
@koaps Would like you to open a PR for this issue
@ajomadlabs sure I can, but I wasn't sure how you would like to handle it.
I'm still new to javascript (I mostly do python) and not that familiar with the other frameworks but if they are running a npm script similar to what Nuxt does, my preference would be to remove any code in launch.js for setting the port and put any port overrides needed in the package.json in the starter-templates.
@koaps It's not a problem even if you are new to javascript. Would always love to see you open a PR resolving this bug post which I could review on it. I probably think giving the flexibility for the users to override the port is necessity.
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,
});
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.
The client port is hardcoded which makes it not possible to provide an alternative port via the package.json.
Steps to reproduce the behavior:
Expected behavior:
to be able to specify port and host in the package.json for scripts
Modified
/usr/lib/node_modules/mevn-cli/lib/commands/serve/launch.js
From:To:
Now it works as expected: