mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
Refactor API URL configuration
This commit is contained in:
parent
d9198cfddf
commit
577b866bb3
|
|
@ -20,12 +20,10 @@ if (!config) {
|
||||||
throw new Error("Config not found");
|
throw new Error("Config not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = `${config.http.bind}:${config.http.bind_port}`;
|
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
const data = await fetch(
|
const data = await fetch(
|
||||||
new URL(`/api/v1/statuses/${route.params.uuid}`, url),
|
new URL(`/api/v1/statuses/${route.params.uuid}`, config.http.url),
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
|
|
|
||||||
|
|
@ -20,28 +20,32 @@ if (!config) {
|
||||||
throw new Error("Config not found");
|
throw new Error("Config not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = `${config.http.bind}:${config.http.bind_port}`;
|
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
const username = (route.params.username as string).replace("@", "");
|
const username = (route.params.username as string).replace("@", "");
|
||||||
|
|
||||||
const id = await fetch(new URL(`/api/v1/accounts/search?q=${username}`, url), {
|
const id = await fetch(
|
||||||
|
new URL(`/api/v1/accounts/search?q=${username}`, config.http.url),
|
||||||
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
},
|
},
|
||||||
})
|
},
|
||||||
|
)
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.catch(() => null);
|
.catch(() => null);
|
||||||
|
|
||||||
let data = null;
|
let data = null;
|
||||||
|
|
||||||
if (id && id.length > 0) {
|
if (id && id.length > 0) {
|
||||||
data = await fetch(new URL(`/api/v1/accounts/${id[0].id}`, url), {
|
data = await fetch(
|
||||||
|
new URL(`/api/v1/accounts/${id[0].id}`, config.http.url),
|
||||||
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
},
|
},
|
||||||
})
|
},
|
||||||
|
)
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.catch(() => ({
|
.catch(() => ({
|
||||||
error: "Failed to fetch user (it probably doesn't exist)",
|
error: "Failed to fetch user (it probably doesn't exist)",
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,9 @@ export default defineEventHandler(async () => {
|
||||||
bind: config?.http.bind,
|
bind: config?.http.bind,
|
||||||
bind_port: config?.http.bind_port,
|
bind_port: config?.http.bind_port,
|
||||||
base_url: config?.http.base_url,
|
base_url: config?.http.base_url,
|
||||||
|
url: config?.http.bind.includes("http")
|
||||||
|
? `${config?.http.bind}:${config?.http.bind_port}`
|
||||||
|
: `http://${config?.http.bind}:${config?.http.bind_port}`,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue