Skip to content

Commit 4a9d59f

Browse files
committed
Remove astro:env call in siteUrlServer.ts since it is not available in context of modules called from astro.config.ts
1 parent f921d66 commit 4a9d59f

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/env.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
interface ImportMetaEnv {
2+
readonly NODE_ENV: string;
3+
}
4+
5+
interface ImportMeta {
6+
readonly env: ImportMetaEnv;
7+
}

src/lib/config/siteUrlServer.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
/**
22
* Server-side method to determine correct URL
33
*/
4-
import { DEV_SERVER_PORT } from "astro:env/client"
4+
import { loadEnv } from 'vite'
55
import { domain } from '../../../package.json' with { type: 'json' }
66
import { isVercel } from '@lib/config/environmentServer'
77

8+
const { DEV_SERVER_PORT } = loadEnv(process.env['NODE_ENV'] ?? 'development', process.cwd(), '')
9+
810
/** Called from astro.config.ts to determine "site" config key */
911
export const getSiteUrl = (): string => {
1012
if (isVercel() && domain) {
1113
console.log(`Using production environment with domain from package.json: ${domain}`)
1214
return `https://${domain}`
13-
} else {
15+
} else if (!!DEV_SERVER_PORT) {
1416
console.log(`Using development environment on port ${DEV_SERVER_PORT}.`)
1517
return `http://localhost:${DEV_SERVER_PORT}`
18+
} else {
19+
console.log(
20+
`Using default value of "http://localhost:4321" for the site URL. DEV_SERVER_PORT is not set in the environment.`
21+
)
22+
return `http://localhost:${DEV_SERVER_PORT}`
1623
}
1724
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
* https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping
113113
* This avoids needing for ts-node to include a top-level key of: "ts-node": { "files": true }
114114
*/
115-
"typeRoots": ["./@types/**/*.d.ts", "./node_modules/@types/**/*.d.ts"],
115+
"typeRoots": ["./@types/**/*.d.ts", "./node_modules/@types/**/*.d.ts", "./src/env.d.ts"],
116116
/** switches to the upcoming ECMA runtime behavior instead of TypeScript's legacy behavior. */
117117
"useDefineForClassFields": true,
118118
/**

0 commit comments

Comments
 (0)