@@ -7,6 +7,7 @@ describe("createDomainLabels", () => {
77 const baseDomain : Domain = {
88 host : "example.com" ,
99 port : 8080 ,
10+ customEntrypoint : null ,
1011 https : false ,
1112 uniqueConfigKey : 1 ,
1213 customCertResolver : null ,
@@ -240,4 +241,134 @@ describe("createDomainLabels", () => {
240241 "traefik.http.routers.test-app-1-websecure.middlewares=stripprefix-test-app-1,addprefix-test-app-1" ,
241242 ) ;
242243 } ) ;
244+
245+ it ( "should create basic labels for custom entrypoint" , async ( ) => {
246+ const labels = await createDomainLabels (
247+ appName ,
248+ { ...baseDomain , customEntrypoint : "custom" } ,
249+ "custom" ,
250+ ) ;
251+ expect ( labels ) . toEqual ( [
252+ "traefik.http.routers.test-app-1-custom.rule=Host(`example.com`)" ,
253+ "traefik.http.routers.test-app-1-custom.entrypoints=custom" ,
254+ "traefik.http.services.test-app-1-custom.loadbalancer.server.port=8080" ,
255+ "traefik.http.routers.test-app-1-custom.service=test-app-1-custom" ,
256+ ] ) ;
257+ } ) ;
258+
259+ it ( "should create https labels for custom entrypoint" , async ( ) => {
260+ const labels = await createDomainLabels (
261+ appName ,
262+ {
263+ ...baseDomain ,
264+ https : true ,
265+ customEntrypoint : "custom" ,
266+ certificateType : "letsencrypt" ,
267+ } ,
268+ "custom" ,
269+ ) ;
270+ expect ( labels ) . toEqual ( [
271+ "traefik.http.routers.test-app-1-custom.rule=Host(`example.com`)" ,
272+ "traefik.http.routers.test-app-1-custom.entrypoints=custom" ,
273+ "traefik.http.services.test-app-1-custom.loadbalancer.server.port=8080" ,
274+ "traefik.http.routers.test-app-1-custom.service=test-app-1-custom" ,
275+ "traefik.http.routers.test-app-1-custom.tls.certresolver=letsencrypt" ,
276+ ] ) ;
277+ } ) ;
278+
279+ it ( "should add stripPath middleware for custom entrypoint" , async ( ) => {
280+ const labels = await createDomainLabels (
281+ appName ,
282+ {
283+ ...baseDomain ,
284+ customEntrypoint : "custom" ,
285+ path : "/api" ,
286+ stripPath : true ,
287+ } ,
288+ "custom" ,
289+ ) ;
290+
291+ expect ( labels ) . toContain (
292+ "traefik.http.middlewares.stripprefix-test-app-1.stripprefix.prefixes=/api" ,
293+ ) ;
294+ expect ( labels ) . toContain (
295+ "traefik.http.routers.test-app-1-custom.middlewares=stripprefix-test-app-1" ,
296+ ) ;
297+ } ) ;
298+
299+ it ( "should add internalPath middleware for custom entrypoint" , async ( ) => {
300+ const labels = await createDomainLabels (
301+ appName ,
302+ {
303+ ...baseDomain ,
304+ customEntrypoint : "custom" ,
305+ internalPath : "/hello" ,
306+ } ,
307+ "custom" ,
308+ ) ;
309+
310+ expect ( labels ) . toContain (
311+ "traefik.http.middlewares.addprefix-test-app-1.addprefix.prefix=/hello" ,
312+ ) ;
313+ expect ( labels ) . toContain (
314+ "traefik.http.routers.test-app-1-custom.middlewares=addprefix-test-app-1" ,
315+ ) ;
316+ } ) ;
317+
318+ it ( "should add path prefix in rule for custom entrypoint" , async ( ) => {
319+ const labels = await createDomainLabels (
320+ appName ,
321+ {
322+ ...baseDomain ,
323+ customEntrypoint : "custom" ,
324+ path : "/api" ,
325+ } ,
326+ "custom" ,
327+ ) ;
328+
329+ expect ( labels ) . toContain (
330+ "traefik.http.routers.test-app-1-custom.rule=Host(`example.com`) && PathPrefix(`/api`)" ,
331+ ) ;
332+ } ) ;
333+
334+ it ( "should combine all middlewares for custom entrypoint" , async ( ) => {
335+ const labels = await createDomainLabels (
336+ appName ,
337+ {
338+ ...baseDomain ,
339+ customEntrypoint : "custom" ,
340+ path : "/api" ,
341+ stripPath : true ,
342+ internalPath : "/hello" ,
343+ } ,
344+ "custom" ,
345+ ) ;
346+
347+ expect ( labels ) . toContain (
348+ "traefik.http.middlewares.stripprefix-test-app-1.stripprefix.prefixes=/api" ,
349+ ) ;
350+ expect ( labels ) . toContain (
351+ "traefik.http.middlewares.addprefix-test-app-1.addprefix.prefix=/hello" ,
352+ ) ;
353+ expect ( labels ) . toContain (
354+ "traefik.http.routers.test-app-1-custom.middlewares=stripprefix-test-app-1,addprefix-test-app-1" ,
355+ ) ;
356+ } ) ;
357+
358+ it ( "should not add redirect-to-https for custom entrypoint even with https" , async ( ) => {
359+ const labels = await createDomainLabels (
360+ appName ,
361+ {
362+ ...baseDomain ,
363+ customEntrypoint : "custom" ,
364+ https : true ,
365+ certificateType : "letsencrypt" ,
366+ } ,
367+ "custom" ,
368+ ) ;
369+
370+ const middlewareLabel = labels . find ( ( l ) => l . includes ( ".middlewares=" ) ) ;
371+ // Should not contain redirect-to-https since there's only one router
372+ expect ( middlewareLabel ) . toBeUndefined ( ) ;
373+ } ) ;
243374} ) ;
0 commit comments