-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): Implement
healthcheck
HTTP API endpoint.
Fixes #838.
- Loading branch information
1 parent
63cd2ee
commit 1fde951
Showing
4 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
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 @@ | ||
// eslint-disable-next-line import/no-unassigned-import | ||
import 'regenerator-runtime/runtime.js'; | ||
import {assert} from 'chai'; | ||
import request from 'supertest'; | ||
|
||
import {server} from '../../../imports/_test/fixtures'; | ||
|
||
import absoluteURL from '../../../imports/app/absoluteURL'; | ||
|
||
const app = absoluteURL('api/healthcheck'); | ||
|
||
server(__filename, () => { | ||
it('works', async () => { | ||
const response = await request(app).get(`/`); | ||
|
||
assert.equal(response.status, 200); | ||
assert.equal(response.text, 'OK'); | ||
}); | ||
}); |
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,25 @@ | ||
import process from 'process'; | ||
|
||
import express from 'express'; | ||
|
||
import isProduction from '../../../imports/app/isProduction'; | ||
import isReady from '../../../imports/app/isReady'; | ||
|
||
import {pipe} from '../rateLimit'; | ||
|
||
import rateLimiter from './rateLimiter'; | ||
|
||
const routes = express(); | ||
|
||
routes.set('trust proxy', process.env.HTTP_FORWARDED_COUNT); | ||
|
||
if (isProduction()) { | ||
routes.use(pipe(rateLimiter)); | ||
} | ||
|
||
routes.get(`/`, async (_req, res, _next) => { | ||
await isReady(); | ||
res.status(200).send('OK'); | ||
}); | ||
|
||
export default routes; |
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,11 @@ | ||
import {RateLimiterMemory} from 'rate-limiter-flexible'; | ||
|
||
const rateLimiter = new RateLimiterMemory({ | ||
// NOTE key prefix is not necessary since each RateLimiterMemory is backed | ||
// by its own storage. | ||
keyPrefix: '', | ||
points: 15, // NOTE 6 points | ||
duration: 60, // NOTE Per minute | ||
}); | ||
|
||
export default rateLimiter; |
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