mirror of
https://github.com/fosrl/pangolin.git
synced 2025-07-18 01:34:43 +02:00
check for user before getting orgs, create default config
This commit is contained in:
parent
6d9731f071
commit
717aa09daa
6 changed files with 49 additions and 29 deletions
|
@ -22,6 +22,7 @@ RUN npm install --omit=dev
|
|||
|
||||
COPY --from=builder /app/.next ./.next
|
||||
COPY --from=builder /app/dist ./dist
|
||||
COPY ./config/config.example.yml /app/dist/
|
||||
COPY server/db/names.json /app/dist/names.json
|
||||
|
||||
CMD ["npm", "start"]
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
app:
|
||||
name: Pangolin
|
||||
base_url: http://localhost:3000
|
||||
log_level: debug
|
||||
log_level: warning
|
||||
save_logs: "false"
|
||||
|
||||
server:
|
||||
external_port: "3000"
|
||||
internal_port: "3001"
|
||||
internal_hostname: localhost
|
||||
secure_cookies: "false"
|
||||
internal_hostname: pangolin
|
||||
secure_cookies: "true"
|
||||
|
||||
traefik:
|
||||
cert_resolver: "letsencrypt"
|
||||
http_entrypoint: "http"
|
||||
https_entrypoint: "https"
|
||||
http_entrypoint: "web"
|
||||
https_entrypoint: "websecure"
|
||||
|
||||
rate_limit:
|
||||
window_minutes: "1"
|
||||
max_requests: "100"
|
||||
max_requests: "100"
|
|
@ -84,6 +84,25 @@ if (fs.existsSync(configFilePath1)) {
|
|||
} else if (fs.existsSync(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) {
|
||||
throw new Error("No configuration file found");
|
||||
|
|
|
@ -33,12 +33,6 @@ export function buildTraefikConfig(
|
|||
|
||||
const tls = {
|
||||
certResolver: config.traefik.cert_resolver,
|
||||
// domains: [ // TODO: figure out if this is neccessary
|
||||
// {
|
||||
// main: baseDomain,
|
||||
// sans: ["*." + baseDomain],
|
||||
// },
|
||||
// ],
|
||||
};
|
||||
|
||||
const http: any = {
|
||||
|
@ -59,8 +53,8 @@ export function buildTraefikConfig(
|
|||
},
|
||||
};
|
||||
for (const target of targets) {
|
||||
const routerName = `router-${target.targetId}`;
|
||||
const serviceName = `service-${target.targetId}`;
|
||||
const routerName = `${target.targetId}-router`;
|
||||
const serviceName = `${target.targetId}-service`;
|
||||
|
||||
http.routers![routerName] = {
|
||||
entryPoints: [target.ssl ? config.traefik.https_entrypoint : config.traefik.https_entrypoint],
|
||||
|
|
|
@ -8,6 +8,7 @@ import { internal } from "@app/api";
|
|||
import { AxiosResponse } from "axios";
|
||||
import { authCookieHeader } from "@app/api/cookies";
|
||||
import { redirect } from "next/navigation";
|
||||
import { verifySession } from "@app/lib/auth/verifySession";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: `Dashboard - ${process.env.NEXT_PUBLIC_APP_NAME}`,
|
||||
|
@ -21,22 +22,26 @@ export default async function RootLayout({
|
|||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
// let orgs: ListOrgsResponse["orgs"] = [];
|
||||
// try {
|
||||
// const res = await internal.get<AxiosResponse<ListOrgsResponse>>(
|
||||
// `/orgs`,
|
||||
// authCookieHeader(),
|
||||
// );
|
||||
// if (res && res.data.data.orgs) {
|
||||
// orgs = res.data.data.orgs;
|
||||
// }
|
||||
const user = await verifySession();
|
||||
|
||||
// if (!orgs.length) {
|
||||
// redirect(`/setup`);
|
||||
// }
|
||||
// } catch (e) {
|
||||
// console.error("Error fetching orgs", e);
|
||||
// }
|
||||
let orgs: ListOrgsResponse["orgs"] = [];
|
||||
if (user) {
|
||||
try {
|
||||
const res = await internal.get<AxiosResponse<ListOrgsResponse>>(
|
||||
`/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 (
|
||||
<html suppressHydrationWarning>
|
||||
|
|
|
@ -13,6 +13,7 @@ export default async function Page() {
|
|||
|
||||
if (!user) {
|
||||
redirect("/auth/login");
|
||||
return;
|
||||
}
|
||||
|
||||
let orgs: ListOrgsResponse["orgs"] = [];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue