-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(watcher): create a route to healthcheck /version
- Loading branch information
Showing
12 changed files
with
1,440 additions
and
539 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const { getLogger, APP_NAMESPACE } = require('../utils/logger'); | ||
const logger = getLogger('controllers:error'); | ||
const { | ||
ValidationError, | ||
InternalError, | ||
ObjectNotFoundError, | ||
errorHandler, | ||
} = require('../utils/error'); | ||
|
||
const errorMiddleware = async (ctx, next) => { | ||
try { | ||
await next(); | ||
} catch (error) { | ||
errorHandler(error, { type: 'request', request: ctx.request }); | ||
if (error instanceof InternalError) { | ||
logger.log('InternalError:', error.message); | ||
ctx.status = 500; | ||
ctx.body = { | ||
ok: false, | ||
error: 'Something went wrong, you should retry later.', | ||
}; | ||
return; | ||
} | ||
if (error instanceof ValidationError) { | ||
logger.log('ValidationError:', error.message); | ||
ctx.status = 400; | ||
ctx.body = { ok: false, error: error.message }; | ||
return; | ||
} | ||
if (error instanceof ObjectNotFoundError) { | ||
logger.log('ObjectNotFoundError:', error.message); | ||
ctx.status = 404; | ||
ctx.body = { ok: false, error: error.message }; | ||
return; | ||
} | ||
logger.log('Error:', error.message); | ||
ctx.status = 500; | ||
ctx.body = { | ||
ok: false, | ||
error: 'Internal error', | ||
}; | ||
} | ||
}; | ||
|
||
module.exports = { | ||
errorMiddleware, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const Router = require('koa-router'); | ||
const { getVersion } = require('../services/version'); | ||
const { getLogger } = require('../utils/logger'); | ||
const logger = getLogger('controllers:router'); | ||
|
||
|
||
const router = new Router(); | ||
|
||
// version | ||
router.get('/version', async (ctx) => { | ||
logger.log('GET /version'); | ||
const version = await getVersion(); | ||
ctx.body = { ok: true, version }; | ||
}); | ||
|
||
|
||
module.exports = { | ||
router, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
const { start } = require('./app'); | ||
const { start, app } = require('./app'); | ||
const { serverPort } = require('./config'); | ||
const { getLogger, APP_NAMESPACE } = require('./utils/logger'); | ||
const logger = getLogger(APP_NAMESPACE); | ||
|
||
app.listen(serverPort); | ||
logger.log(`Server listening on port ${serverPort}`); | ||
|
||
start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { version } = require('../../package.json'); | ||
|
||
const getVersion = () => version; | ||
|
||
module.exports = { | ||
getVersion, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters