Skip to content

Commit

Permalink
Merge pull request #399 from metrico/qryn_view-routing
Browse files Browse the repository at this point in the history
Qryn view routing
  • Loading branch information
akvlad authored Dec 4, 2023
2 parents cd8cf5b + 9bfc399 commit 40b6987
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions qryn_bun.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,17 @@ export default async() => {
const serveView = fs.existsSync(path.join(__dirname, 'view/index.html'))
if (serveView) {
app.plug(group(path.join(__dirname, 'view')));
for (const fakePath of ['/plugins', '/users', '/datasources', '/datasources/:ds']) {
app.get(fakePath,
(ctx) =>
file(path.join(__dirname, 'view', 'index.html'))(ctx))
}
}

app.use(404, (ctx) => {
if (ctx.error && ctx.error.name === 'UnauthorizedError') {
return new Response(ctx.error.message, {status: 401, headers: { 'www-authenticate': 'Basic' }})
}
if (serveView) {
return file(path.join(__dirname, 'view', 'index.html'))(ctx);
}
return wrapper(handle404)
})
app.port = process.env.PORT || 3100
Expand Down
6 changes: 6 additions & 0 deletions qryn_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,12 @@ let fastify = require('fastify')({
root: path.join(__dirname, 'view'),
prefix: '/'
})
const idx = fs.readFileSync('view/index.html', 'utf8')
for (const fakePath of ['/plugins', '/users', '/datasources', '/datasources/:ds']) {
fastify.get(fakePath,
(req, reply) =>
reply.code(200).header('Content-Type', 'text/html').send(idx))
}
}

// Run API Service
Expand Down

0 comments on commit 40b6987

Please sign in to comment.