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

Qryn view routing #399

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading