2021-03-24 21:11:14 +00:00
|
|
|
const { docker } = require('../../../libs/docker')
|
2021-04-19 07:46:05 +00:00
|
|
|
const { saveServerLog } = require('../../../libs/logging')
|
2021-03-24 21:11:14 +00:00
|
|
|
|
|
|
|
|
module.exports = async function (fastify) {
|
|
|
|
|
fastify.get('/', async (request, reply) => {
|
2021-04-15 20:40:44 +00:00
|
|
|
try {
|
|
|
|
|
const { name } = request.query
|
|
|
|
|
const service = await docker.engine.getService(`${name}_${name}`)
|
|
|
|
|
const logs = (await service.logs({ stdout: true, stderr: true, timestamps: true })).toString().split('\n').map(l => l.slice(8)).filter((a) => a)
|
|
|
|
|
return { logs }
|
|
|
|
|
} catch (error) {
|
2021-04-19 07:46:05 +00:00
|
|
|
await saveServerLog(error)
|
|
|
|
|
throw new Error(error)
|
2021-04-15 20:40:44 +00:00
|
|
|
}
|
2021-03-24 21:11:14 +00:00
|
|
|
})
|
|
|
|
|
}
|