Add content type for JSON

This commit is contained in:
Wietse Wind
2023-10-06 12:49:55 +02:00
parent 0f88633dfc
commit 053057c8b7

View File

@@ -34,17 +34,26 @@ if (!wss) {
// return next() // return next()
// }) // })
app.use('/', function renderHomepage(req, res, next) { app.use('/',
res.setHeader('content-type', 'text/html'); (req, res, next) => {
if (req.url.split('?')?.[0].match(/\.json$/i)) {
res.setHeader('content-type', 'application/json')
}
next()
},
function renderHomepage(req, res, next) {
// res.setHeader('content-type', 'text/html')
if (req.url === '' || req.url === '/') { if (req.url === '' || req.url === '/') {
res.render('public_html/index.html', { res.render('public_html/index.html', {
infraConfig: {
wssNodes: typeof process.env?.NODES === 'string' ? process.env.NODES.split(',') : null,
unlurl: process.env?.UNLURL ?? null,
unlkey: process.env?.UNLKEY ?? null,
},
config: { config: {
networkid: process.env?.NETWORKID ?? null, networkid: process.env?.NETWORKID ?? null,
urlprefix: process.env?.URL_PREFIX ?? null, urlprefix: process.env?.URL_PREFIX ?? null,
nodes: process.env?.NODES ?? null, requiredTxFields: typeof process.env?.FIELDSREQUIRED === 'string' ? process.env.FIELDSREQUIRED.split(',') : null,
fields: process.env?.FIELDSREQUIRED ?? null,
unlurl: process.env?.UNLURL ?? null,
unlkey: process.env?.UNLKEY ?? null,
}, },
stats: { stats: {
lastLedger: lastLedger ?? null, lastLedger: lastLedger ?? null,
@@ -55,9 +64,12 @@ if (!wss) {
} else { } else {
next() next()
} }
},express.static('./store/')) },
express.static('./store/'),
)
app.use('/health', (req, res) => { app.use('/health', (req, res) => {
res.setHeader('content-type', 'application/json')
res.json({ res.json({
uptime: new Date() - startDate, uptime: new Date() - startDate,
lastLedger: lastLedger ?? null, lastLedger: lastLedger ?? null,