Skip to content

Commit 18a5f08

Browse files
committed
add basePath
1 parent 8a1d48d commit 18a5f08

5 files changed

Lines changed: 48 additions & 7 deletions

File tree

examples/config/config.env

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
# Core Application Settings
33
############################
44

5+
# Public URL where WoL Redirect is accessible
6+
# Used for absolute redirects, links, and OAuth flows
7+
# Example: https://wol-red.mydomain.com
8+
APP_URL=
9+
10+
# Base path the application is served from
11+
# Leave empty or "/" if served from the root
12+
# Example: /wol or /apps/wol
13+
BASE_PATH=/
14+
515
# Path to the service mapping configuration file
616
CONFIG_PATH=/app/config/mapping.json
717

src/app.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import express from "express"
1+
import express, { Router } from "express"
22
import { createServer } from "http"
33
import cookieParser from "cookie-parser"
44

@@ -43,8 +43,12 @@ await Init()
4343

4444
app.use(cookieParser())
4545

46-
app.use("/", auth())
47-
app.use("/", wol())
46+
const rootRouter = Router()
47+
48+
rootRouter.use("/", auth())
49+
rootRouter.use("/", wol())
50+
51+
app.use(env.ENV.basePath, rootRouter)
4852

4953
app.use((err, req, res, next) => {
5054
log.logger.error(err)

src/auth.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,25 @@ function registerFakeAuth() {
248248
}
249249

250250
export function Router() {
251-
try {
252-
redirectURL = new URL(ENV.redirectURL)
253-
} catch {}
254-
255251
if (ENV.useOauth) {
252+
if (ENV.redirectURL) {
253+
try {
254+
redirectURL = new URL(ENV.redirectURL)
255+
} catch {}
256+
}
257+
256258
if (!redirectURL) {
257259
logger.error("Error parsing redirect URL: ", ENV.redirectURL)
258260
}
259261

260262
registerOauth()
261263
} else {
264+
if (ENV.appURL) {
265+
try {
266+
redirectURL = new URL(ENV.appURL)
267+
} catch {}
268+
}
269+
262270
registerFakeAuth()
263271
}
264272

src/env.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export const ENV = {
77
port: "6789",
88
logLevel: "info",
99

10+
appURL: "",
11+
basePath: "",
12+
1013
exposeLogs: true,
1114
useOauth: true,
1215

@@ -46,6 +49,21 @@ export function Load() {
4649
ENV.port = process.env.PORT || ENV.port
4750
ENV.logLevel = process.env.LOG_LEVEL || ENV.logLevel
4851

52+
const appUrl = process.env.APP_URL || ""
53+
54+
let basePath = process.env.BASE_PATH || ""
55+
56+
if (appUrl && !basePath) {
57+
try {
58+
const appURL = new URL(appUrl)
59+
basePath = appURL.pathname
60+
} catch {}
61+
}
62+
63+
if (basePath) {
64+
ENV.basePath = ENV.appURL.pathname.replace(/\/$/, "")
65+
}
66+
4967
ENV.redisHost = process.env.REDIS_HOST || ENV.redisHost
5068
ENV.redisPort = process.env.REDIS_PORT || ENV.redisPort
5169
ENV.redisUser = process.env.REDIS_USER || ENV.redisUser

views/home.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
}, 250)
156156
}
157157
},
158+
endpoint: `${window.location.origin}/start`,
158159
})
159160
}
160161

0 commit comments

Comments
 (0)