mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Merge pull request #286 from lorenzomigliorero/fix/server-traefik-config
fix: server traefik config https middleware
This commit is contained in:
commit
1d91131d9a
3
.gitignore
vendored
3
.gitignore
vendored
@ -33,6 +33,9 @@ npm-debug.log*
|
|||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Editor
|
||||||
|
.vscode
|
||||||
|
|
||||||
# Misc
|
# Misc
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*.pem
|
*.pem
|
||||||
|
@ -0,0 +1,97 @@
|
|||||||
|
import { fs, vol } from "memfs";
|
||||||
|
|
||||||
|
vi.mock("node:fs", () => ({
|
||||||
|
...fs,
|
||||||
|
default: fs,
|
||||||
|
}));
|
||||||
|
|
||||||
|
import type { Admin } from "@/server/api/services/admin";
|
||||||
|
import { createDefaultServerTraefikConfig } from "@/server/setup/traefik-setup";
|
||||||
|
import { loadOrCreateConfig } from "@/server/utils/traefik/application";
|
||||||
|
import type { FileConfig } from "@/server/utils/traefik/file-types";
|
||||||
|
import { updateServerTraefik } from "@/server/utils/traefik/web-server";
|
||||||
|
import { beforeEach, expect, test, vi } from "vitest";
|
||||||
|
|
||||||
|
const baseAdmin: Admin = {
|
||||||
|
createdAt: "",
|
||||||
|
authId: "",
|
||||||
|
adminId: "string",
|
||||||
|
githubAppId: null,
|
||||||
|
githubAppName: null,
|
||||||
|
serverIp: null,
|
||||||
|
certificateType: "none",
|
||||||
|
host: null,
|
||||||
|
githubClientId: null,
|
||||||
|
githubClientSecret: null,
|
||||||
|
githubInstallationId: null,
|
||||||
|
githubPrivateKey: null,
|
||||||
|
githubWebhookSecret: null,
|
||||||
|
letsEncryptEmail: null,
|
||||||
|
sshPrivateKey: null,
|
||||||
|
enableDockerCleanup: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
vol.reset();
|
||||||
|
createDefaultServerTraefikConfig();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Should read the configuration file", () => {
|
||||||
|
const config: FileConfig = loadOrCreateConfig("dokploy");
|
||||||
|
|
||||||
|
expect(config.http?.routers?.["dokploy-router-app"]?.service).toBe(
|
||||||
|
"dokploy-service-app",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Should apply redirect-to-https", () => {
|
||||||
|
updateServerTraefik(
|
||||||
|
{
|
||||||
|
...baseAdmin,
|
||||||
|
certificateType: "letsencrypt",
|
||||||
|
},
|
||||||
|
"example.com",
|
||||||
|
);
|
||||||
|
|
||||||
|
const config: FileConfig = loadOrCreateConfig("dokploy");
|
||||||
|
|
||||||
|
expect(config.http?.routers?.["dokploy-router-app"]?.middlewares).toContain(
|
||||||
|
"redirect-to-https",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Should change only host when no certificate", () => {
|
||||||
|
updateServerTraefik(baseAdmin, "example.com");
|
||||||
|
|
||||||
|
const config: FileConfig = loadOrCreateConfig("dokploy");
|
||||||
|
|
||||||
|
expect(config.http?.routers?.["dokploy-router-app-secure"]).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Should not touch config without host", () => {
|
||||||
|
const originalConfig: FileConfig = loadOrCreateConfig("dokploy");
|
||||||
|
|
||||||
|
updateServerTraefik(baseAdmin, null);
|
||||||
|
|
||||||
|
const config: FileConfig = loadOrCreateConfig("dokploy");
|
||||||
|
|
||||||
|
expect(originalConfig).toEqual(config);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Should remove web-secure if https rollback to http", () => {
|
||||||
|
const originalConfig: FileConfig = loadOrCreateConfig("dokploy");
|
||||||
|
|
||||||
|
updateServerTraefik(
|
||||||
|
{ ...baseAdmin, certificateType: "letsencrypt" },
|
||||||
|
"example.com",
|
||||||
|
);
|
||||||
|
|
||||||
|
updateServerTraefik({ ...baseAdmin, certificateType: "none" }, "example.com");
|
||||||
|
|
||||||
|
const config: FileConfig = loadOrCreateConfig("dokploy");
|
||||||
|
|
||||||
|
expect(config.http?.routers?.["dokploy-router-app-secure"]).toBeUndefined();
|
||||||
|
expect(
|
||||||
|
config.http?.routers?.["dokploy-router-app"]?.middlewares,
|
||||||
|
).not.toContain("redirect-to-https");
|
||||||
|
});
|
@ -129,7 +129,6 @@
|
|||||||
"zod-form-data": "^2.0.2"
|
"zod-form-data": "^2.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tsconfig-paths": "4.2.0",
|
|
||||||
"@biomejs/biome": "1.8.3",
|
"@biomejs/biome": "1.8.3",
|
||||||
"@commitlint/cli": "^19.3.0",
|
"@commitlint/cli": "^19.3.0",
|
||||||
"@commitlint/config-conventional": "^19.2.2",
|
"@commitlint/config-conventional": "^19.2.2",
|
||||||
@ -154,10 +153,12 @@
|
|||||||
"husky": "^9.0.11",
|
"husky": "^9.0.11",
|
||||||
"lint-staged": "^15.2.7",
|
"lint-staged": "^15.2.7",
|
||||||
"localtunnel": "2.0.2",
|
"localtunnel": "2.0.2",
|
||||||
|
"memfs": "^4.11.0",
|
||||||
"postcss": "^8.4.31",
|
"postcss": "^8.4.31",
|
||||||
"prettier": "^3.2.4",
|
"prettier": "^3.2.4",
|
||||||
"prettier-plugin-tailwindcss": "^0.5.11",
|
"prettier-plugin-tailwindcss": "^0.5.11",
|
||||||
"tailwindcss": "^3.4.1",
|
"tailwindcss": "^3.4.1",
|
||||||
|
"tsconfig-paths": "4.2.0",
|
||||||
"tsx": "^4.7.0",
|
"tsx": "^4.7.0",
|
||||||
"typescript": "^5.4.2",
|
"typescript": "^5.4.2",
|
||||||
"vite-tsconfig-paths": "4.3.2",
|
"vite-tsconfig-paths": "4.3.2",
|
||||||
|
@ -104,8 +104,7 @@ export const createDefaultServerTraefikConfig = () => {
|
|||||||
[`${appName}-router-app`]: {
|
[`${appName}-router-app`]: {
|
||||||
rule: `Host(\`${appName}.docker.localhost\`) && PathPrefix(\`/\`)`,
|
rule: `Host(\`${appName}.docker.localhost\`) && PathPrefix(\`/\`)`,
|
||||||
service: `${appName}-service-app`,
|
service: `${appName}-service-app`,
|
||||||
entryPoints: ["web", "websecure"],
|
entryPoints: ["web"],
|
||||||
tls: {},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
services: {
|
services: {
|
||||||
|
@ -19,14 +19,20 @@ export const updateServerTraefik = (
|
|||||||
|
|
||||||
const currentRouterConfig = config.http.routers[`${appName}-router-app`];
|
const currentRouterConfig = config.http.routers[`${appName}-router-app`];
|
||||||
|
|
||||||
if (currentRouterConfig) {
|
if (currentRouterConfig && newHost) {
|
||||||
if (newHost) {
|
currentRouterConfig.rule = `Host(\`${newHost}\`)`;
|
||||||
currentRouterConfig.rule = `Host(\`${newHost}\`)`;
|
|
||||||
}
|
|
||||||
if (admin?.certificateType === "letsencrypt") {
|
if (admin?.certificateType === "letsencrypt") {
|
||||||
currentRouterConfig.tls = { certResolver: "letsencrypt" };
|
config.http.routers[`${appName}-router-app-secure`] = {
|
||||||
} else if (admin?.certificateType === "none") {
|
...currentRouterConfig,
|
||||||
currentRouterConfig.tls = undefined;
|
entryPoints: ["web-secure"],
|
||||||
|
tls: { certResolver: "letsencrypt" },
|
||||||
|
};
|
||||||
|
|
||||||
|
currentRouterConfig.middlewares = ["redirect-to-https"];
|
||||||
|
} else {
|
||||||
|
delete config.http.routers[`${appName}-router-app-secure`];
|
||||||
|
currentRouterConfig.middlewares = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18427
pnpm-lock.yaml
18427
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user