mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
Reorganize FE
This commit is contained in:
parent
e27a80c40a
commit
354493133c
10 changed files with 112 additions and 63 deletions
29
packages/frontend/composables/useConfig.ts
Normal file
29
packages/frontend/composables/useConfig.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
export const useConfig = async () => {
|
||||
let host = useRequestHeader("X-Forwarded-Host");
|
||||
|
||||
if (!host && process.server) {
|
||||
host = process.env.BUILD_HOST;
|
||||
}
|
||||
|
||||
if (!host?.includes("http")) {
|
||||
// On server, this will be some kind of localhost
|
||||
host = `http://${host}`;
|
||||
}
|
||||
|
||||
if (process.client) {
|
||||
host = useRequestURL().origin.toString();
|
||||
}
|
||||
|
||||
console.log(host);
|
||||
|
||||
if (!host) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: "No X-Forwarded-Host header found",
|
||||
});
|
||||
}
|
||||
|
||||
return await fetch(new URL("/api/_fe/config", host)).then((res) =>
|
||||
res.json(),
|
||||
);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue