Skip to content

Commit 5aeee43

Browse files
author
Sam Thorogood
authored
health check setup (GoogleChrome#1289)
1 parent ab345e3 commit 5aeee43

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

app.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ handlers:
1818
script: auto
1919
secure: always
2020
redirect_http_response_code: 301
21+
22+
readiness_check:
23+
path: "/_check"
24+
check_interval_sec: 5
25+
timeout_sec: 4
26+
failure_threshold: 2
27+
success_threshold: 2
28+
app_start_timeout_sec: 300

package-lock.json

+3-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"gulp-imagemin": "^7.1.0",
5858
"html-minifier": "^4.0.0",
5959
"js-cookie": "^2.2.1",
60+
"js-yaml": "^4.1.0",
6061
"lit-element": "^2.4.0",
6162
"lit-html": "^1.3.0",
6263
"node-fetch": "^2.6.0",
@@ -94,7 +95,6 @@
9495
"husky": "^4.3.0",
9596
"install": "^0.13.0",
9697
"iso-639-1": "^2.1.4",
97-
"js-yaml": "^4.1.0",
9898
"lodash.get": "^4.4.2",
9999
"markdown-it": "^12.0.1",
100100
"markdown-it-anchor": "^8.1.2",

server/health-check.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2021 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Included for types only.
18+
// eslint-disable-next-line no-unused-vars
19+
const express = require('express');
20+
21+
/**
22+
* @type {express.RequestHandler}
23+
*/
24+
const healthCheckHandler = (req, res, next) => {
25+
if (req.url === '/_check') {
26+
res.send('Ok');
27+
return res.end();
28+
}
29+
return next();
30+
};
31+
32+
module.exports = healthCheckHandler;

server/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const {notFoundHandler} = require('./not-found');
2121
const {buildRedirectHandler} = require('./redirect');
2222
const {buildUniqueRedirectHandler} = require('./unique-redirect');
2323
const unknownDomainRedirectHandler = require('./unknown-domain');
24+
const healthCheckHandler = require('./health-check');
2425

2526
const app = express();
2627

@@ -63,6 +64,7 @@ const handlers = [
6364
...staticPaths.map(staticPath => express.static(staticPath)),
6465
redirectHandler,
6566
uniqueRedirectHandler,
67+
healthCheckHandler,
6668
notFoundHandler,
6769
];
6870

0 commit comments

Comments
 (0)