Skip to content

Commit

Permalink
db test route
Browse files Browse the repository at this point in the history
  • Loading branch information
ais-one committed Sep 13, 2023
1 parent 6e3ab40 commit 1b7dd5a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
6 changes: 4 additions & 2 deletions apps/app-sample/public/demo-express/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
<h1>Basic Express <a href="index.html">Back</a></h1>
<ul>
<li><a href="#" onclick="testAPI('/api/healthcheck')">Express Server Health Check</a></li>
<li><a href="#" onclick="testAPI('/api/app-sample/healthcheck')">App Sample Health Check</a></li>
<li><a href="#" onclick="testCors()">Test XHR CORS</a></li>
<li><a href="#" onclick="testAPI('/api/app-sample/tests/outbound')">Test outbound unblocked</a></li>
<li><a href="#" onclick="testAPI('/api/app-sample/check-db?conn=knex1&sql=SELECT 1')">Test DB Connection</a></li>
<li><a href="#" onclick="testAPI('/api/app-sample/tests/outbound?url=https://httpbin.org/get')">Test outbound unblocked</a></li>
<li><a href="#" onclick="testStream('/api/app-sample/tests/stream')">Test return stream</a></li>
<li><a href="#" onclick="testAPI('/api/app-sample/tests/error')">Handled Exception - /api/error - caught by middleware</a></li>
<li><a href="#" onclick="testAPI('/api/app-sample/tests/error-not-found')">404 Not Found Error</a></li>
Expand Down Expand Up @@ -49,7 +51,7 @@ <h1>Basic Express <a href="index.html">Back</a></h1>
outputEl.innerHTML = JSON.stringify(rv, null, 2)
} catch (e) {
outputEl.innerHTML = JSON.stringify(e, null, 2)
res.status(500).json()
console.log(e)
}
}

Expand Down
22 changes: 20 additions & 2 deletions apps/app-sample/routes/base.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
'use strict'

const express = require('express')
const s = require('@es-labs/node/services')

module.exports = express.Router()
.get('/', (req, res) => res.send('app-sample OK'))
.get('/healthcheck', (req, res) => res.send('app-sample/healthcheck OK'))
.get('/', (req, res) => res.send({ status: 'app-sample OK' }))
.get('/healthcheck', (req, res) => res.send({ status: 'app-sample/healthcheck OK' }))
.get('/check-db', async (req, res) => {
const connectionName = req.query.conn || 'knex1'
const connQuery = req.query.sql || 'SELECT 1'
try {
const clientName = s.get(connectionName).context.client.config.client
// const a = s.get('knex1').context.client.config.client
// console.log(a, a.config, a.database, a.context.client.config.client)
const rv = await s.get(connectionName).raw(connQuery)
return res.status(200).json({
connectionName,
db: clientName
})
} catch (e) {
console.log(e)
return res.status(500).json(e)
}
})

0 comments on commit 1b7dd5a

Please sign in to comment.