Skip to content
Snippets Groups Projects
Commit dd8eca6c authored by Michael Zigldrum's avatar Michael Zigldrum
Browse files

Added option to host ui on a specified sub path.

parent 3f3f3e36
No related branches found
No related tags found
No related merge requests found
......@@ -11,3 +11,4 @@ data:
UI_HOST: {{ .Values.application.properties.ui_host }}
COOKIE_SECRET: {{ .Values.application.properties.cookie_secret }}
NODE_TLS_REJECT_UNAUTHORIZED: {{ .Values.application.properties.node_tls_reject_unauthorized }}
APP_BASE_URL_PATH: {{ .Values.appliation.properties.app_base_url_path }}
......@@ -111,5 +111,6 @@ application:
ui_host: your ui host
cookie_secret: a cookie secret
node_tls_reject_unauthorized: "1"
app_base_url_path: "/ui"
configmap:
name: nsd-ui-configmap
ZONEMGR_URL=http://localhost:16001
OIDC_ISSUER_URL=http://localhost:8002/realms/gxfs-dev-test
#OIDC_ISSUER_URL=http://localhost:8002/realms/gxfs-dev-test
OIDC_ISSUER_URL=https://auth-cloud-wallet.xfsc.dev/realms/train
#OIDC_SPECIAL_AUTH_HOST=localhost:8002
OIDC_CLIENT_ID=xfsctest
OIDC_CLIENT_SECRET=6GRWUQXZ3p6U0gzVIp0mInAdf1zWuQEJ
OIDC_SCOPES="openid email profile"
UI_HOST=http://localhost:8001
COOKIE_SECRET=ashdhfghsaghasghasfahsjkf
NODE_TLS_REJECT_UNAUTHORIZED="0"
APP_BASE_URL_PATH=/ui
......@@ -18,7 +18,9 @@ function ZoneDataView() {
useEffect(() => {
setLoading(true)
console.log(`Loading data from backend.`)
fetch('/api/zonedata', {
const basePath = window.location.pathname
console.log('Detected basePath: ' + basePath)
fetch(`${basePath}/api/zonedata`, {
redirect: 'manual'
})
.then(async (res) => {
......
......@@ -56,7 +56,7 @@ async function authCallback(req, res) {
ACCESS TOKEN:
${tokenSet.access_token}
%%%%%%%%%%%%%%%%%%%%%%%%%%%`)
res.redirect('/')
res.redirect(`${process.env.APP_BASE_URL_PATH || '/'}`)
} catch (error) {
res.status(500).send('Error: ' + error.message)
console.log(`ERROR in /auth/callback ->
......
......@@ -4,6 +4,11 @@ const ViteExpress = require('vite-express')
const app = express()
buildApp(app).then((server) => {
ViteExpress.config( {
inlineViteConfig: {
base: process.env.APP_BASE_URL_PATH || '/'
}
})
ViteExpress.bind(app, server)
}).catch((error) => {
console.log('Error starting server!: ' + error)
......
......@@ -31,7 +31,7 @@ async function checkIfAccessTokenExists (req, res, next) {
next()
}
} catch (error) {
res.redirect('/auth/login')
res.redirect(`${process.env.APP_BASE_URL_PATH || ''}/auth/login`)
}
}
......
......@@ -19,12 +19,12 @@ async function buildApp (app) {
let client
if (process.env.NODE_ENV !== 'test') {
console.log(`Attempting Discovery of .well-known information for configured OIDC Issuer "${ISSUER_URL}"`)
const issuer = await openidClient.Issuer.discover(ISSUER_URL)
issuer = await openidClient.Issuer.discover(ISSUER_URL)
console.log(`Successfully completed discovery for OIDC Issuer "${ISSUER_URL}`)
const client = new issuer.Client({
client = new issuer.Client({
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
redirect_uris: [`${UI_HOST}/auth/callback`],
redirect_uris: [`${UI_HOST}${process.env.APP_BASE_URL_PATH || ''}/auth/callback`],
response_types: ['code']
})
}
......@@ -52,13 +52,9 @@ async function buildApp (app) {
}
next()
})
const tokenMiddleware = require('./middleware/authTokenMiddleware')
const zoneDataHandler = require('./handlers/zoneDataHandler')
app.get('/api/zonedata', tokenMiddleware, zoneDataHandler.getZoneData)
app.get('/auth/login', require('./handlers/authHandler').login)
app.get('/auth/logout', tokenMiddleware, require('./handlers/authHandler').logout)
app.get('/auth/callback', require('./handlers/authHandler').authCallback)
const basePath = process.env.APP_BASE_URL_PATH || '/'
console.log('Starting Express with basePath: ' + basePath)
app.use(basePath, defineRoutes())
console.log('Express App built.')
return app.listen(port, '0.0.0.0', () => {
console.log(`Express app is listening on port ${port}`)
......@@ -69,6 +65,16 @@ async function buildApp (app) {
STACK: ${error.stack}`)
process.exit(1)
}
}
function defineRoutes() {
const router = express.Router()
const tokenMiddleware = require('./middleware/authTokenMiddleware')
const zoneDataHandler = require('./handlers/zoneDataHandler')
router.get('/api/zonedata', tokenMiddleware, zoneDataHandler.getZoneData)
router.get('/auth/login', require('./handlers/authHandler').login)
router.get('/auth/logout', tokenMiddleware, require('./handlers/authHandler').logout)
router.get('/auth/callback', require('./handlers/authHandler').authCallback)
return router
}
module.exports = buildApp
\ No newline at end of file
......@@ -12,7 +12,7 @@ describe('GET /api/zonedata', () => {
.get('/view-zone')
.reply(200, mockData)
const server = await router(express())
const response = await supertest(server).get('/api/zonedata')
const response = await supertest(server).get('/ui/api/zonedata')
console.log(response)
expect(response.statusCode).toBe(200)
expect(response.body).toEqual(mockData)
......@@ -22,7 +22,7 @@ describe('GET /api/zonedata', () => {
describe('GET /api/zonedata', () => {
it('should fail and return 500 error', async ()=> {
const server = await router(express())
const response = await supertest(server).get('/api/zonedata')
const response = await supertest(server).get('/ui/api/zonedata')
expect(response.statusCode).toBe(500)
})
})
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment