Skip to content

Instantly share code, notes, and snippets.

@Aschen
Created November 1, 2021 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aschen/773e70fdbab249ab5ebc2ed72e87ba98 to your computer and use it in GitHub Desktop.
Save Aschen/773e70fdbab249ab5ebc2ed72e87ba98 to your computer and use it in GitHub Desktop.
Expose Admin Console in a Kuzzle controller
app.controller.register('redirect', {
actions: {
proxy: {
handler: async request => {
const { css, js, img, fonts } = request.input.args;
let url;
let contentType;
if (css) {
url = `http://console.kuzzle.io/css/${css}`
contentType = 'text/css';
}
else if (js) {
url = `http://console.kuzzle.io/js/${js}`
contentType = 'text/javascript';
}
else if (img) {
url = `http://console.kuzzle.io/js/${js}`
contentType = null;
}
else if (fonts) {
url = `http://console.kuzzle.io/fonts/${fonts}`
contentType = null;
}
else {
url = 'http://console.kuzzle.io/';
contentType = 'text/html';
}
const response = await httpClient.request(url, 'GET')
request.response.configure({
format: 'raw',
headers: {
'Content-Length': response.body.length.toString(),
'Content-Type': contentType,
}
});
return response.body;
},
http: [
{ verb: 'get', path: 'console' },
{ verb: 'get', path: 'css/:css' },
{ verb: 'get', path: 'js/:js' },
{ verb: 'get', path: 'img/:img' },
{ verb: 'get', path: 'fonts/:fonts' },
]
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment