mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 00:18: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");
|
||||
}
|
||||
|
||||
const url = `${config.http.bind}:${config.http.bind_port}`;
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
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: {
|
||||
Accept: "application/json",
|
||||
|
|
|
|||
|
|
@ -20,28 +20,32 @@ if (!config) {
|
|||
throw new Error("Config not found");
|
||||
}
|
||||
|
||||
const url = `${config.http.bind}:${config.http.bind_port}`;
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
const username = (route.params.username as string).replace("@", "");
|
||||
|
||||
const id = await fetch(new URL(`/api/v1/accounts/search?q=${username}`, url), {
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
const id = await fetch(
|
||||
new URL(`/api/v1/accounts/search?q=${username}`, config.http.url),
|
||||
{
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
},
|
||||
},
|
||||
})
|
||||
)
|
||||
.then((res) => res.json())
|
||||
.catch(() => null);
|
||||
|
||||
let data = null;
|
||||
|
||||
if (id && id.length > 0) {
|
||||
data = await fetch(new URL(`/api/v1/accounts/${id[0].id}`, url), {
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
data = await fetch(
|
||||
new URL(`/api/v1/accounts/${id[0].id}`, config.http.url),
|
||||
{
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
},
|
||||
},
|
||||
})
|
||||
)
|
||||
.then((res) => res.json())
|
||||
.catch(() => ({
|
||||
error: "Failed to fetch user (it probably doesn't exist)",
|
||||
|
|
|
|||
|
|
@ -13,6 +13,9 @@ export default defineEventHandler(async () => {
|
|||
bind: config?.http.bind,
|
||||
bind_port: config?.http.bind_port,
|
||||
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