Merge pull request #1517 from hackmdio/fix/getStatus

Fix getStatus caused "TypeError: Converting circular structure to JSON"
This commit is contained in:
Raccoon 2020-05-17 13:31:03 +08:00 committed by GitHub
commit 641e569a49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View File

@ -298,10 +298,12 @@ function getStatus () {
} }
}) })
.catch(function (err) { .catch(function (err) {
return logger.error('count user failed: ' + err) logger.error('count user failed: ' + err)
return Promise.reject(new Error('count user failed: ' + err))
}) })
}).catch(function (err) { }).catch(function (err) {
return logger.error('count note failed: ' + err) logger.error('count note failed: ' + err)
return Promise.reject(new Error('count note failed: ' + err))
}) })
} }
@ -772,8 +774,7 @@ function queueForConnect (socket) {
const noteId = socket.noteId const noteId = socket.noteId
logger.info('SERVER connected a client to [' + noteId + ']:') logger.info('SERVER connected a client to [' + noteId + ']:')
logger.info(JSON.stringify(user)) logger.info(JSON.stringify(user))
// logger.info(notes); getStatus().then(function (data) {
getStatus(function (data) {
logger.info(JSON.stringify(data)) logger.info(JSON.stringify(data))
}) })
} }

View File

@ -4,14 +4,19 @@ const realtime = require('../realtime/realtime')
const config = require('../config') const config = require('../config')
exports.getStatus = async (req, res) => { exports.getStatus = async (req, res) => {
const data = await realtime.getStatus()
res.set({ res.set({
'Cache-Control': 'private', // only cache by client 'Cache-Control': 'private', // only cache by client
'X-Robots-Tag': 'noindex, nofollow', // prevent crawling 'X-Robots-Tag': 'noindex, nofollow', // prevent crawling
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}) })
try {
const data = await realtime.getStatus()
res.send(data) res.send(data)
} catch (e) {
console.error(e)
res.status(500).send(e.toString())
}
} }
exports.getMetrics = async (req, res) => { exports.getMetrics = async (req, res) => {