Ensure CLI flags override function-style server config (#5110)
This commit is contained in:
parent
0db9c08a8d
commit
0edfdd3259
3 changed files with 19 additions and 2 deletions
5
.changeset/eighty-planes-kneel.md
Normal file
5
.changeset/eighty-planes-kneel.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Ensure CLI flags override function-style server config
|
|
@ -271,8 +271,18 @@ export function createRelativeSchema(cmd: string, fileProtocolRoot: URL) {
|
||||||
.default({}),
|
.default({}),
|
||||||
server: z.preprocess(
|
server: z.preprocess(
|
||||||
// preprocess
|
// preprocess
|
||||||
(val) =>
|
(val) => {
|
||||||
typeof val === 'function' ? val({ command: cmd === 'dev' ? 'dev' : 'preview' }) : val,
|
if (typeof val === 'function') {
|
||||||
|
const result = val({ command: cmd === 'dev' ? 'dev' : 'preview' });
|
||||||
|
// @ts-expect-error revive attached prop added from CLI flags
|
||||||
|
if (val.port) result.port = val.port;
|
||||||
|
// @ts-expect-error revive attached prop added from CLI flags
|
||||||
|
if (val.host) result.host = val.host;
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
},
|
||||||
// validate
|
// validate
|
||||||
z
|
z
|
||||||
.object({
|
.object({
|
||||||
|
|
|
@ -4,4 +4,6 @@ import preact from '@astrojs/preact';
|
||||||
// https://astro.build/config
|
// https://astro.build/config
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
integrations: [preact()],
|
integrations: [preact()],
|
||||||
|
// make sure CLI flags have precedence
|
||||||
|
server: () => ({ port: 3000 })
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue