refactor(libs): share the origin env schema
`origin` (scheme and host only) lives in @lumina/libs/env, so the apps stop repeating it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
297f0b2cbd
commit
0e8347d6d3
|
|
@ -1,4 +1,5 @@
|
||||||
export { createClientEnv } from './env.client';
|
export { createClientEnv } from './env.client';
|
||||||
|
export { origin } from './schemas';
|
||||||
export type {
|
export type {
|
||||||
ClientEnvOptions,
|
ClientEnvOptions,
|
||||||
EnvSchema,
|
EnvSchema,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
import * as v from 'valibot';
|
||||||
|
|
||||||
|
/** `https://api.lumina.ir`, not `https://api.lumina.ir/` or `https://api.lumina.ir/v1`. */
|
||||||
|
function isOrigin(value: string): boolean {
|
||||||
|
try {
|
||||||
|
return new URL(value).origin === value;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A scheme and host only, such as `http://gateway:3000`: paths are joined to it, so a trailing
|
||||||
|
* slash or a path would give `//v1` or `/v1/v1`.
|
||||||
|
*/
|
||||||
|
export const origin = v.pipe(
|
||||||
|
v.string(),
|
||||||
|
v.url(),
|
||||||
|
v.check(
|
||||||
|
isOrigin,
|
||||||
|
'Must be an origin such as https://api.example.com, with no path or trailing slash.',
|
||||||
|
),
|
||||||
|
);
|
||||||
Loading…
Reference in New Issue