Skip to content

Commit 7bece64

Browse files
demianrenzullipbakaus
authored andcommitted
Enable SSL by default (#119)
* Changes to app.yaml, package.json. and server.js, to enable SSL by default. Added express-sslify dependency to ensure HSTS, and helmet dependency, to be aligned with expressjs security best practices. * Removing condition for tasks API on server.js file.
1 parent 9c1af3b commit 7bece64

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

amp-pwa-reader/app.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
env: flex
22
runtime: nodejs
3+
4+
handlers:
5+
- url: /.*
6+
script: IGNORED
7+
secure: always

amp-pwa-reader/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"connect-history-api-fallback": "*",
1414
"del": "*",
1515
"express": "^4.16.2",
16+
"express-sslify": "^1.2.0",
1617
"gulp": "github:gulpjs/gulp#4.0",
1718
"gulp-autoprefixer": "*",
1819
"gulp-concat": "*",
@@ -24,6 +25,7 @@
2425
"gulp-sass": "*",
2526
"gulp-sourcemaps": "*",
2627
"gulp-uglify": "*",
28+
"helmet": "^3.12.1",
2729
"memory-cache": "^0.2.0",
2830
"request": "^2.81.0",
2931
"uglify-es": "*",

amp-pwa-reader/src/server/server.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,22 @@ const fs = require('fs');
2020
const path = require('path');
2121
const memCache = require('memory-cache');
2222
const pubBackend = require('./Backend.js');
23+
const enforce = require('express-sslify');
24+
const helmet = require('helmet');
25+
26+
const ENVIRONMENT_PRODUCTION = 'production';
2327

2428
const app = express();
2529
const pub = new pubBackend();
2630

31+
app.use(helmet());
32+
33+
if (app.get('env') === ENVIRONMENT_PRODUCTION) {
34+
app.use((req, res, next) => {
35+
enforce.HTTPS({ trustProtoHeader: true })(req, res, next);
36+
});
37+
}
38+
2739
// how long (in seconds) to cache requests for main feed and for any article
2840
const cacheDurations = {feed: 600, article: 3600};
2941
const feedURL = 'https://query.yahooapis.com/v1/public/yql';

0 commit comments

Comments
 (0)