class Ping extends CortexObject {
// run first no api key set, will use that of the caller.
@log({ traceError: true })
@route('* *', { priority: 999 })
static count({ req, res, next, runtime }) {
try {
res.setHeader('Content-Type', 'application/x-ndjson')
} catch(err) {}
res.write(JSON.stringify({
route: `${runtime.configuration.method} /routes/${runtime.configuration.path}`,
key: req.client.key,
principal: script.principal.email,
resource: runtime.metadata.resource
})+'\n')
next()
}
// run second, but only if pingCount is 1. pins the app to c_dashboard
@log({ traceError: true })
@route('POST pingCount/1', {
apiKey: 'c_dashboard',
priority: 2
})
static countAgain({ req, res, next, runtime }) {
try {
res.setHeader('Content-Type', 'application/x-ndjson')
} catch(err) {}
res.write(JSON.stringify({
route: `${runtime.configuration.method} /routes/${runtime.configuration.path}`,
key: req.client.key,
principal: script.principal.email,
resource: runtime.metadata.resource
})+'\n')
next()
}
// run last
@log({ traceError: true })
@route('POST pingCount/:num', { priority: 1 })
static countOnceMore({ req, res, runtime }) {
try {
res.setHeader('Content-Type', 'application/x-ndjson')
} catch(err) {}
res.write(JSON.stringify({
route: `${runtime.configuration.method} /routes/${runtime.configuration.path}`,
key: req.client.key,
principal: script.principal.email,
resource: runtime.metadata.resource
})+'\n')
}
}