diff --git a/spec/file_caching_test.js b/spec/file_caching_test.js index 5dfc979c962a199c169a655bdec9f738b13e9f98..c545637e4046f8c714c28c310018e41ed51abf94 100644 --- a/spec/file_caching_test.js +++ b/spec/file_caching_test.js @@ -44,6 +44,7 @@ describe('File caching service', () => { '/main.css': (req, res) => res.setHeader('content-type', 'text/css').status(200).send('.foo { color: #000; }') }) + await request(app).get('/ready') }) afterEach(() => { diff --git a/src/createApp.js b/src/createApp.js index c9d3ab232b910b6e2da271fbd966e4f3d6a55640..f68d9b312fa3a1b2595b156bbf6d8c0819d84b0b 100644 --- a/src/createApp.js +++ b/src/createApp.js @@ -35,6 +35,15 @@ export function createApp () { const httpLogger = pinoHttp({ logger, autoLogging: { ignorePaths } }) const healthCheck = new health.HealthChecker() + const readinessCheck = new health.ReadinessCheck('getDependencies', async function () { + try { + await getDependencies() + } catch (e) { + logger.error(`Failed to get dependencies: ${e.message}`) + throw e + } + }) + healthCheck.registerReadinessCheck(readinessCheck) // Application-level middleware app.use(httpLogger) @@ -70,14 +79,12 @@ export function createApp () { }) app.get('/', async (req, res, next) => { - await getDependencies() const { 'content-type': contentType, content } = fileCache.get('/index.html') if (content) return res.setHeader('content-type', contentType).status(200).send(content) next() }) app.use(async (req, res, next) => { - await getDependencies() const { 'content-type': contentType, content } = fileCache.get(req.path) if (content) return res.setHeader('content-type', contentType).status(200).send(content) next()