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({}),
|
||||
server: z.preprocess(
|
||||
// preprocess
|
||||
(val) =>
|
||||
typeof val === 'function' ? val({ command: cmd === 'dev' ? 'dev' : 'preview' }) : val,
|
||||
(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
|
||||
z
|
||||
.object({
|
||||
|
|
|
@ -4,4 +4,6 @@ import preact from '@astrojs/preact';
|
|||
// https://astro.build/config
|
||||
export default defineConfig({
|
||||
integrations: [preact()],
|
||||
// make sure CLI flags have precedence
|
||||
server: () => ({ port: 3000 })
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue