Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev - Move Hawtio backend logics in app/webpack.config.cjs devServer to @hawtio/backend-middleware #899

Open
tadayosi opened this issue Apr 24, 2024 · 0 comments
Labels
area/backend-middleware help wanted Extra attention is needed kind/refactoring Code improvements that don't add or change features

Comments

@tadayosi
Copy link
Member

Now that we have the backend-middleware in hawtio-next #891, we can refactor it more easily. The hawtio backend mocking code tends to be bloated and would be nice to be moved to the backend-middleware package, so that the other downstream hawtio applications don't need to replicate the same mocking logic for their development.

setupMiddlewares: (middlewares, devServer) => {
devServer.app.use(bodyParser.json())
// Redirect / or /hawtio to /hawtio/
if (publicPath && publicPath !== '/') {
devServer.app.get('/', (_, res) => res.redirect(`${publicPath}/`))
devServer.app.get(`${publicPath}$`, (_, res) => res.redirect(`${publicPath}/`))
}
const username = 'developer'
const proxyEnabled = true
// TODO: Currently self-hosting remotes don't work despite no errors thrown
const plugin = [
{
url: 'http://localhost:3000',
scope: 'app',
module: './remote',
pluginEntry: 'registerRemote',
},
]
// Keycloak
const keycloakEnabled = false
const keycloakClientConfig = {
realm: 'hawtio-demo',
clientId: 'hawtio-client',
url: 'http://localhost:18080/',
jaas: false,
pkceMethod: 'S256',
}
// Hawtio backend API mock
let login = true
devServer.app.get(`${publicPath}/user`, (_, res) => {
login ? res.send(`"${username}"`) : res.sendStatus(403)
})
devServer.app.post(`${publicPath}/auth/login`, (req, res) => {
// Test authentication throttling with username 'throttled'
const { username } = req.body
if (username === 'throttled') {
res.append('Retry-After', 10) // 10 secs
res.sendStatus(429)
return
}
login = true
res.send(String(login))
})
devServer.app.get(`${publicPath}/auth/logout`, (_, res) => {
login = false
res.redirect(`${publicPath}/login`)
})
const oidcEnabled = false
const oidcConfig = {
method: 'oidc',
provider: 'https://login.microsoftonline.com/11111111-2222-3333-4444-555555555555/v2.0',
client_id: '66666666-7777-8888-9999-000000000000',
response_mode: 'fragment',
scope: 'openid email profile api://hawtio-server/Jolokia.Access',
redirect_uri: 'http://localhost:3000/hawtio/',
code_challenge_method: 'S256',
prompt: 'login',
}
devServer.app.get(`${publicPath}/auth/config`, (_, res) => {
res.type('application/json')
if (oidcEnabled) {
res.send(JSON.stringify(oidcConfig))
} else {
res.send('{}')
}
})
devServer.app.get(`${publicPath}/auth/config/session-timeout`, (_, res) => {
res.type('application/json')
res.send('{}')
})
devServer.app.get(`${publicPath}/proxy/enabled`, (_, res) => res.send(String(proxyEnabled)))
devServer.app.get(`${publicPath}/plugin`, (_, res) => res.send(JSON.stringify(plugin)))
devServer.app.get(`${publicPath}/keycloak/enabled`, (_, res) => res.send(String(keycloakEnabled)))
devServer.app.get(`${publicPath}/keycloak/client-config`, (_, res) =>
res.send(JSON.stringify(keycloakClientConfig)),
)
devServer.app.get(`${publicPath}/keycloak/validate-subject-matches`, (_, res) => res.send('true'))
// Hawtio backend middleware should be run before other middlewares (thus 'unshift')
// in order to handle GET requests to the proxied Jolokia endpoint.
middlewares.unshift({
name: 'hawtio-backend',
path: `${publicPath}/proxy`,
middleware: hawtioBackend({
// Uncomment it if you want to see debug log for Hawtio backend
logLevel: 'debug',
}),
})
return middlewares
},

@tadayosi tadayosi added kind/refactoring Code improvements that don't add or change features area/backend-middleware help wanted Extra attention is needed labels Apr 24, 2024
@tadayosi tadayosi changed the title Dev - Move Hawtio logics in app/webpack.config.cjs devServer to @hawtio/backend-middleware Dev - Move Hawtio backend logics in app/webpack.config.cjs devServer to @hawtio/backend-middleware Apr 24, 2024
@lhein lhein moved this from New to Backlog in Kanban Board Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/backend-middleware help wanted Extra attention is needed kind/refactoring Code improvements that don't add or change features
Projects
Status: Backlog
Development

No branches or pull requests

1 participant