Embded frontend inside go binary

This will simplify the self hosting of the platform.

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-03-09 15:30:28 +01:00
parent 2c82dbad39
commit 123a538d82
40 changed files with 527 additions and 262 deletions

View File

@@ -11,7 +11,7 @@ const fetchRelay: FetchFunction = async (
request,
variables,
_,
uploadables,
uploadables
) => {
const requestInit: RequestInit = {
method: "POST",
@@ -27,7 +27,7 @@ const fetchRelay: FetchFunction = async (
operationName: request.name,
query: request.text,
variables: variables,
}),
})
);
const uploadableMap: {
@@ -59,7 +59,10 @@ const fetchRelay: FetchFunction = async (
});
}
const response = await fetch(buildEndpoint("/console/v1/query"), requestInit);
const response = await fetch(
buildEndpoint("/api/console/v1/query"),
requestInit
);
const json = await response.json();
@@ -68,8 +71,8 @@ const fetchRelay: FetchFunction = async (
`Error fetching GraphQL query '${
request.name
}' with variables '${JSON.stringify(variables)}': ${JSON.stringify(
json.errors,
)}`,
json.errors
)}`
);
}

View File

@@ -21,7 +21,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
const checkAuth = async (): Promise<boolean> => {
try {
// Make a request to an endpoint that requires authentication
const response = await fetch(buildEndpoint("/console/v1/query"), {
const response = await fetch(buildEndpoint("/api/console/v1/query"), {
method: "POST",
credentials: "include",
headers: {

View File

@@ -20,7 +20,7 @@ export default function LoginPage() {
setIsLoading(true);
try {
const response = await fetch(buildEndpoint("/console/v1/auth/login"), {
const response = await fetch(buildEndpoint("/api/console/v1/auth/login"), {
method: "POST",
headers: {
"Content-Type": "application/json",

View File

@@ -32,7 +32,7 @@ export default function RegisterPage() {
setIsLoading(true);
try {
const response = await fetch(buildEndpoint("/console/v1/auth/register"), {
const response = await fetch(buildEndpoint("/api/console/v1/auth/register"), {
method: "POST",
headers: {
"Content-Type": "application/json",

View File

@@ -1,9 +1,15 @@
export function buildEndpoint(path: string): string {
const host = process.env.API_SERVER_HOST!;
if (!host) {
return path;
}
const formattedHost =
host.startsWith("http://") || host.startsWith("https://")
? host
: `https://${host}`;
const url = new URL(formattedHost);
if (path) {