check for user before getting orgs, create default config

This commit is contained in:
Milo Schwartz 2024-10-22 23:58:00 -04:00
parent 6d9731f071
commit 717aa09daa
No known key found for this signature in database
6 changed files with 49 additions and 29 deletions

View file

@ -22,6 +22,7 @@ RUN npm install --omit=dev
COPY --from=builder /app/.next ./.next COPY --from=builder /app/.next ./.next
COPY --from=builder /app/dist ./dist COPY --from=builder /app/dist ./dist
COPY ./config/config.example.yml /app/dist/
COPY server/db/names.json /app/dist/names.json COPY server/db/names.json /app/dist/names.json
CMD ["npm", "start"] CMD ["npm", "start"]

View file

@ -1,20 +1,20 @@
app: app:
name: Pangolin name: Pangolin
base_url: http://localhost:3000 base_url: http://localhost:3000
log_level: debug log_level: warning
save_logs: "false" save_logs: "false"
server: server:
external_port: "3000" external_port: "3000"
internal_port: "3001" internal_port: "3001"
internal_hostname: localhost internal_hostname: pangolin
secure_cookies: "false" secure_cookies: "true"
traefik: traefik:
cert_resolver: "letsencrypt" cert_resolver: "letsencrypt"
http_entrypoint: "http" http_entrypoint: "web"
https_entrypoint: "https" https_entrypoint: "websecure"
rate_limit: rate_limit:
window_minutes: "1" window_minutes: "1"
max_requests: "100" max_requests: "100"

View file

@ -84,6 +84,25 @@ if (fs.existsSync(configFilePath1)) {
} else if (fs.existsSync(configFilePath2)) { } else if (fs.existsSync(configFilePath2)) {
environment = loadConfig(configFilePath2); environment = loadConfig(configFilePath2);
} }
if (!environment) {
const exampleConfigPath = path.join("config.example.yml");
if (fs.existsSync(exampleConfigPath)) {
try {
const exampleConfigContent = fs.readFileSync(exampleConfigPath, "utf8");
fs.writeFileSync(configFilePath1, exampleConfigContent, "utf8");
environment = loadConfig(configFilePath1);
} catch (error) {
if (error instanceof Error) {
throw new Error(
`Error creating configuration file from example: ${error.message}`,
);
}
throw error;
}
} else {
throw new Error("No configuration file found and no example configuration available");
}
}
if (!environment) { if (!environment) {
throw new Error("No configuration file found"); throw new Error("No configuration file found");

View file

@ -33,12 +33,6 @@ export function buildTraefikConfig(
const tls = { const tls = {
certResolver: config.traefik.cert_resolver, certResolver: config.traefik.cert_resolver,
// domains: [ // TODO: figure out if this is neccessary
// {
// main: baseDomain,
// sans: ["*." + baseDomain],
// },
// ],
}; };
const http: any = { const http: any = {
@ -59,8 +53,8 @@ export function buildTraefikConfig(
}, },
}; };
for (const target of targets) { for (const target of targets) {
const routerName = `router-${target.targetId}`; const routerName = `${target.targetId}-router`;
const serviceName = `service-${target.targetId}`; const serviceName = `${target.targetId}-service`;
http.routers![routerName] = { http.routers![routerName] = {
entryPoints: [target.ssl ? config.traefik.https_entrypoint : config.traefik.https_entrypoint], entryPoints: [target.ssl ? config.traefik.https_entrypoint : config.traefik.https_entrypoint],

View file

@ -8,6 +8,7 @@ import { internal } from "@app/api";
import { AxiosResponse } from "axios"; import { AxiosResponse } from "axios";
import { authCookieHeader } from "@app/api/cookies"; import { authCookieHeader } from "@app/api/cookies";
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { verifySession } from "@app/lib/auth/verifySession";
export const metadata: Metadata = { export const metadata: Metadata = {
title: `Dashboard - ${process.env.NEXT_PUBLIC_APP_NAME}`, title: `Dashboard - ${process.env.NEXT_PUBLIC_APP_NAME}`,
@ -21,22 +22,26 @@ export default async function RootLayout({
}: Readonly<{ }: Readonly<{
children: React.ReactNode; children: React.ReactNode;
}>) { }>) {
// let orgs: ListOrgsResponse["orgs"] = []; const user = await verifySession();
// try {
// const res = await internal.get<AxiosResponse<ListOrgsResponse>>(
// `/orgs`,
// authCookieHeader(),
// );
// if (res && res.data.data.orgs) {
// orgs = res.data.data.orgs;
// }
// if (!orgs.length) { let orgs: ListOrgsResponse["orgs"] = [];
// redirect(`/setup`); if (user) {
// } try {
// } catch (e) { const res = await internal.get<AxiosResponse<ListOrgsResponse>>(
// console.error("Error fetching orgs", e); `/orgs`,
// } authCookieHeader(),
);
if (res && res.data.data.orgs) {
orgs = res.data.data.orgs;
}
if (!orgs.length) {
redirect(`/setup`);
}
} catch (e) {
console.error("Error fetching orgs", e);
}
}
return ( return (
<html suppressHydrationWarning> <html suppressHydrationWarning>

View file

@ -13,6 +13,7 @@ export default async function Page() {
if (!user) { if (!user) {
redirect("/auth/login"); redirect("/auth/login");
return;
} }
let orgs: ListOrgsResponse["orgs"] = []; let orgs: ListOrgsResponse["orgs"] = [];