mirror of
https://github.com/andwati/dokploy.git
synced 2026-10-18 11:12:56 +00:00
fix: server traefik config
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
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);
|
||||
});
|
||||
@@ -154,6 +154,7 @@
|
||||
"husky": "^9.0.11",
|
||||
"lint-staged": "^15.2.7",
|
||||
"localtunnel": "2.0.2",
|
||||
"memfs": "^4.11.0",
|
||||
"postcss": "^8.4.31",
|
||||
"prettier": "^3.2.4",
|
||||
"prettier-plugin-tailwindcss": "^0.5.11",
|
||||
|
||||
Generated
+74
@@ -360,6 +360,9 @@ importers:
|
||||
localtunnel:
|
||||
specifier: 2.0.2
|
||||
version: 2.0.2
|
||||
memfs:
|
||||
specifier: ^4.11.0
|
||||
version: 4.11.0
|
||||
postcss:
|
||||
specifier: ^8.4.31
|
||||
version: 8.4.35
|
||||
@@ -1232,6 +1235,24 @@ packages:
|
||||
'@jridgewell/[email protected]':
|
||||
resolution: {integrity: sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==}
|
||||
|
||||
'@jsonjoy.com/[email protected]':
|
||||
resolution: {integrity: sha512-q6XAnWQDIMA3+FTiOYajoYqySkO+JSat0ytXGSuRdq9uXE7o92gzuQwQM14xaCRlBLGq3v5miDGC4vkVTn54xA==}
|
||||
engines: {node: '>=10.0'}
|
||||
peerDependencies:
|
||||
tslib: '2'
|
||||
|
||||
'@jsonjoy.com/[email protected]':
|
||||
resolution: {integrity: sha512-aOcSN4MeAtFROysrbqG137b7gaDDSmVrl5mpo6sT/w+kcXpWnzhMjmY/Fh/sDx26NBxyIE7MB1seqLeCAzy9Sg==}
|
||||
engines: {node: '>=10.0'}
|
||||
peerDependencies:
|
||||
tslib: '2'
|
||||
|
||||
'@jsonjoy.com/[email protected]':
|
||||
resolution: {integrity: sha512-Cebt4Vk7k1xHy87kHY7KSPLT77A7Ev7IfOblyLZhtYEhrdQ6fX4EoLq3xOQ3O/DRMEh2ok5nyC180E+ABS8Wmw==}
|
||||
engines: {node: '>=10.0'}
|
||||
peerDependencies:
|
||||
tslib: '2'
|
||||
|
||||
'@juggle/[email protected]':
|
||||
resolution: {integrity: sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA==}
|
||||
|
||||
@@ -4375,6 +4396,10 @@ packages:
|
||||
engines: {node: '>=18'}
|
||||
hasBin: true
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-Y93lCzHYgGWdrJ66yIktxiaGULYc6oGiABxhcO5AufBeOyoIdZF7bIfLaOrbM0iGIOXQQgxxRrFEnb+Y6w1n4A==}
|
||||
engines: {node: '>=10.18'}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
@@ -4763,6 +4788,10 @@ packages:
|
||||
resolution: {integrity: sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==}
|
||||
engines: {node: '>= 0.6'}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-+6kz90/YQoZuHvg3rn1CGPMZfEMaU5xe7xIavZMNiom2RNesiI8S37p9O9n+PlIUnUgretjLdM6HnqpZYl3X2g==}
|
||||
engines: {node: '>= 4.0.0'}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-UBWmJpLZd5STPm7PMUlOw/TSy972M+z8gcyQ5veOnSDRREz/0bmpyTfKt3/51DhEBqCZQn1udM/5flcSPYhkdQ==}
|
||||
|
||||
@@ -5958,6 +5987,12 @@ packages:
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-hsqsJsFMsV+aD4s3CWKk85ep/3I9XzYV/IXaSouJMYIoDlgyi11cBhsqYe9/geRfB0YIikBQg6raRaM+nIMP9g==}
|
||||
engines: {node: '>=10.18'}
|
||||
peerDependencies:
|
||||
tslib: ^2
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==}
|
||||
|
||||
@@ -5996,6 +6031,12 @@ packages:
|
||||
resolution: {integrity: sha512-aXJDbk6SnumuaZSANd21XAo15ucCDE38H4fkqiGsc3MhCK+wOlZvLP9cB/TvpHT0mOyWgC4Z8EwRlzqYSUzdsA==}
|
||||
engines: {node: '>= 0.4'}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-dpev9ABuLWdEubk+cIaI9cHwRNNDjkBBLXTwI4UCUFdQ5xXKqNXoK4FEciw/vxf+NQ7Cb7sGUyeUtORvHIdRXQ==}
|
||||
engines: {node: '>=10.0'}
|
||||
peerDependencies:
|
||||
tslib: '2'
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-eUxrowp4F1QEGk/i7Sa+Xl8Crlfp7J0AXxX1QdJEQKQYMWhgMbCIgyQvpO3Q0P9oyTrNQxRLlRipDS44a8EtRw==}
|
||||
|
||||
@@ -7444,6 +7485,22 @@ snapshots:
|
||||
'@jridgewell/resolve-uri': 3.1.2
|
||||
'@jridgewell/sourcemap-codec': 1.4.15
|
||||
|
||||
'@jsonjoy.com/[email protected]([email protected])':
|
||||
dependencies:
|
||||
tslib: 2.6.2
|
||||
|
||||
'@jsonjoy.com/[email protected]([email protected])':
|
||||
dependencies:
|
||||
'@jsonjoy.com/base64': 1.1.2([email protected])
|
||||
'@jsonjoy.com/util': 1.3.0([email protected])
|
||||
hyperdyperid: 1.2.0
|
||||
thingies: 1.21.0([email protected])
|
||||
tslib: 2.6.2
|
||||
|
||||
'@jsonjoy.com/[email protected]([email protected])':
|
||||
dependencies:
|
||||
tslib: 2.6.2
|
||||
|
||||
'@juggle/[email protected]': {}
|
||||
|
||||
'@leichtgewicht/[email protected]': {}
|
||||
@@ -11087,6 +11144,8 @@ snapshots:
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]:
|
||||
dependencies:
|
||||
safer-buffer: 2.1.2
|
||||
@@ -11447,6 +11506,13 @@ snapshots:
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]:
|
||||
dependencies:
|
||||
'@jsonjoy.com/json-pack': 1.0.4([email protected])
|
||||
'@jsonjoy.com/util': 1.3.0([email protected])
|
||||
tree-dump: 1.0.2([email protected])
|
||||
tslib: 2.6.2
|
||||
|
||||
[email protected]:
|
||||
dependencies:
|
||||
d: 1.0.2
|
||||
@@ -12675,6 +12741,10 @@ snapshots:
|
||||
dependencies:
|
||||
any-promise: 1.3.0
|
||||
|
||||
[email protected]([email protected]):
|
||||
dependencies:
|
||||
tslib: 2.6.2
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]:
|
||||
@@ -12702,6 +12772,10 @@ snapshots:
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]([email protected]):
|
||||
dependencies:
|
||||
tslib: 2.6.2
|
||||
|
||||
[email protected]:
|
||||
dependencies:
|
||||
nan: 2.19.0
|
||||
|
||||
@@ -104,8 +104,7 @@ export const createDefaultServerTraefikConfig = () => {
|
||||
[`${appName}-router-app`]: {
|
||||
rule: `Host(\`${appName}.docker.localhost\`) && PathPrefix(\`/\`)`,
|
||||
service: `${appName}-service-app`,
|
||||
entryPoints: ["web", "websecure"],
|
||||
tls: {},
|
||||
entryPoints: ["web"],
|
||||
},
|
||||
},
|
||||
services: {
|
||||
|
||||
@@ -19,14 +19,20 @@ export const updateServerTraefik = (
|
||||
|
||||
const currentRouterConfig = config.http.routers[`${appName}-router-app`];
|
||||
|
||||
if (currentRouterConfig) {
|
||||
if (newHost) {
|
||||
currentRouterConfig.rule = `Host(\`${newHost}\`)`;
|
||||
}
|
||||
if (currentRouterConfig && newHost) {
|
||||
currentRouterConfig.rule = `Host(\`${newHost}\`)`;
|
||||
|
||||
if (admin?.certificateType === "letsencrypt") {
|
||||
currentRouterConfig.tls = { certResolver: "letsencrypt" };
|
||||
} else if (admin?.certificateType === "none") {
|
||||
currentRouterConfig.tls = undefined;
|
||||
config.http.routers[`${appName}-router-app-secure`] = {
|
||||
...currentRouterConfig,
|
||||
entryPoints: ["web-secure"],
|
||||
tls:
|
||||
admin?.certificateType === "letsencrypt"
|
||||
? { certResolver: "letsencrypt" }
|
||||
: undefined,
|
||||
};
|
||||
|
||||
currentRouterConfig.middlewares = ["redirect-to-https"];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user