48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
// vitest/config re-exports Vite's defineConfig with the `test` section added to its type.
|
|
import { defineConfig } from 'vitest/config';
|
|
|
|
/**
|
|
* Resolves the API base URL that Aspire injected. `WithReference(api)` publishes each endpoint as
|
|
* `services__api__<scheme>__<index>`. Outside Aspire the fallback lets a plain `npm run dev` still work.
|
|
*/
|
|
function resolveApiUrl(): string {
|
|
const fromAspire = Object.keys(process.env)
|
|
.filter((key) => key.startsWith('services__api__'))
|
|
// Ascending order puts `http` ahead of `https`; plain HTTP is the simpler hop for a local proxy.
|
|
.sort()
|
|
.map((key) => process.env[key])
|
|
.find((value): value is string => !!value);
|
|
|
|
// Matches the `http` launch profile of TheLivingWorld.Api.
|
|
return fromAspire ?? process.env.API_URL ?? 'http://localhost:5195';
|
|
}
|
|
|
|
export default defineConfig(() => {
|
|
const apiUrl = resolveApiUrl();
|
|
|
|
return {
|
|
server: {
|
|
port: process.env.PORT ? Number(process.env.PORT) : 5173,
|
|
strictPort: true,
|
|
proxy: {
|
|
'/api': {
|
|
target: apiUrl,
|
|
changeOrigin: true,
|
|
// Aspire issues a development certificate the proxy has no reason to distrust.
|
|
secure: false,
|
|
},
|
|
},
|
|
},
|
|
build: {
|
|
target: 'es2022',
|
|
sourcemap: true,
|
|
},
|
|
test: {
|
|
// Everything under test is pure geometry and rule tables, so no DOM is needed. Modules that touch
|
|
// PixiJS are deliberately kept out of these files.
|
|
environment: 'node',
|
|
include: ['src/**/*.test.ts'],
|
|
},
|
|
};
|
|
});
|