mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
Refactor API URL configuration
This commit is contained in:
parent
d9198cfddf
commit
577b866bb3
3 changed files with 18 additions and 13 deletions
|
|
@ -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)",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue