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

fix: createDevServer should not listen port by default #6000

Merged
merged 1 commit into from
Jul 25, 2024
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
7 changes: 7 additions & 0 deletions .changeset/strong-moose-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/app-tools': patch
'@modern-js/server': patch
---

fix: `createDevServer` should not listen port by default
fix: `createDevServer` 默认不应该监听端口
12 changes: 0 additions & 12 deletions packages/server/server/src/createDevServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,5 @@ export async function createDevServer(

await server.init();

nodeServer.listen(
{
host: dev.host || '127.0.0.1',
port: dev.port || '8080',
},
(err?: Error) => {
if (err) {
throw err;
}
},
);

return nodeServer;
}
24 changes: 20 additions & 4 deletions packages/solutions/app-tools/src/commands/dev.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import path from 'node:path';
import { PluginAPI, ResolvedConfigContext } from '@modern-js/core';
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta } from '@modern-js/utils';
import {
DEFAULT_DEV_HOST,
SERVER_DIR,
getMeta,
logger,
} from '@modern-js/utils';
import { createDevServer } from '@modern-js/server';
import { applyPlugins } from '@modern-js/prod-server';
import { loadServerPlugins } from '../utils/loadPlugins';
Expand Down Expand Up @@ -97,6 +102,8 @@ export const dev = async (
...devServerOptions,
};

const host = normalizedConfig.dev?.host || DEFAULT_DEV_HOST;

if (apiOnly) {
const server = await createDevServer(
{
Expand All @@ -106,8 +113,6 @@ export const dev = async (
applyPlugins,
);

const host = normalizedConfig.dev?.host || DEFAULT_DEV_HOST;

server.listen(
{
port,
Expand All @@ -126,7 +131,18 @@ export const dev = async (
applyPlugins,
);

// TODO: set correct server
server.listen(
{
port,
host,
},
(err?: Error) => {
if (err) {
logger.error('Occur error %s, when start dev server', err);
}
},
);

setServer(server);
}
};
Loading