Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent to have empty traefik config in order to prevent domain… #44

Merged
merged 1 commit into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/api/routers/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const domainRouter = createTRPCRouter({
.mutation(async ({ input }) => {
const domain = await findDomainById(input.domainId);
const result = await removeDomainById(input.domainId);
removeDomain(domain.application.appName, domain.uniqueConfigKey);
await removeDomain(domain.application.appName, domain.uniqueConfigKey);

return result;
}),
Expand Down
3 changes: 1 addition & 2 deletions server/api/services/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ export const createApplication = async (
});
}

createTraefikConfig(newApplication.appName);

if (process.env.NODE_ENV === "development") {
createTraefikConfig(newApplication.appName);
await tx.insert(domains).values({
applicationId: newApplication.applicationId,
host: `${newApplication.appName}.docker.localhost`,
Expand Down
13 changes: 11 additions & 2 deletions server/utils/traefik/domain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
createServiceConfig,
loadOrCreateConfig,
removeTraefikConfig,
writeTraefikConfig,
} from "./application";
import type { ApplicationNested } from "../builders";
Expand All @@ -23,7 +24,7 @@ export const manageDomain = async (app: ApplicationNested, domain: Domain) => {
writeTraefikConfig(config, appName);
};

export const removeDomain = (appName: string, uniqueKey: number) => {
export const removeDomain = async (appName: string, uniqueKey: number) => {
const config: FileConfig = loadOrCreateConfig(appName);

const routerKey = `${appName}-router-${uniqueKey}`;
Expand All @@ -35,7 +36,15 @@ export const removeDomain = (appName: string, uniqueKey: number) => {
delete config.http.services[serviceKey];
}

writeTraefikConfig(config, appName);
// verify if is the last router if so we delete the router
if (
config?.http?.routers &&
Object.keys(config?.http?.routers).length === 0
) {
await removeTraefikConfig(appName);
} else {
writeTraefikConfig(config, appName);
}
};

export const createRouterConfig = async (
Expand Down
Loading