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

@@ -0,0 +1,6 @@
POSTHOG_HOST=
POSTHOG_KEY=
FARO_PUSH_URL=
API_SERVER_HOST=

View File

@@ -1 +1,2 @@
!dist/.keep
dist/

20
apps/console/console.go Normal file
View File

@@ -0,0 +1,20 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package console
import "embed"
//go:embed dist
var StaticFiles embed.FS

0
apps/console/dist/.keep vendored Normal file
View File

View File

@@ -70,7 +70,7 @@
"relay": {
"src": "src",
"language": "typescript",
"schema": "../../pkg/api/console/v1/schema.graphql",
"schema": "../../pkg/server/api/console/v1/schema.graphql",
"noFutureProofEnums": true,
"customScalarTypes": {
"Datetime": "string",

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) {