Skip to content

Commit

Permalink
build!: require node.js 10x and up (#37)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Drops support for node.js 6 and node.js 8.
  • Loading branch information
JustinBeckwith committed Apr 8, 2020
1 parent 292464c commit 5ccbe34
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 42 deletions.
33 changes: 13 additions & 20 deletions .circleci/config.yml
Expand Up @@ -3,17 +3,15 @@ workflows:
version: 2
test:
jobs:
- node6
- node8
- node10
- node11
- node12
- node13
- lint
- publish_npm:
requires:
- node6
- node8
- node10
- node11
- node12
- node13
- lint
filters:
branches:
Expand All @@ -26,44 +24,39 @@ unit_tests: &unit_tests
- run: npm test

jobs:
node6:
docker:
- image: node:6
user: node
<<: *unit_tests
node8:
node10:
docker:
- image: node:8
- image: node:10
user: node
<<: *unit_tests
node10:
node12:
docker:
- image: node:10
- image: node:12
user: node
<<: *unit_tests
node11:
node13:
docker:
- image: node:11
- image: node:13
user: node
<<: *unit_tests
lint:
docker:
- image: node:11
- image: node:13
steps:
- checkout
- run: npm install
- run: npm run lint
coverage:
docker:
- image: node:11
- image: node:13
steps:
- checkout
- run: npm install
- run: npm test
- run: npm run coverage
publish_npm:
docker:
- image: node:11
- image: node:13
steps:
- checkout
- run: npm install
Expand Down
4 changes: 2 additions & 2 deletions example/app.js
Expand Up @@ -6,8 +6,8 @@ const app = express();
// Use the yes-https connect middleware. Note - this will only work if NODE_ENV is set to production.
app.use(yes());

app.get('/', (req, res) => {
res.end('Thanks for checking it out!');
app.get('/', (request, response) => {
response.end('Thanks for checking it out!');
});

const server = app.listen(process.env.PORT || 3000, () => {
Expand Down
14 changes: 7 additions & 7 deletions lib/index.js
Expand Up @@ -3,12 +3,12 @@ module.exports = function (options) {
const maxAge = options.maxAge ? options.maxAge : 86400;
const includeSubDomains = options.includeSubDomains === undefined ? true : options.includeSubdomains;

return function (req, res, next) {
return function (request, response, next) {
let ignoreRequest = (process.env.NODE_ENV !== 'production');
const secure = req.connection.encrypted || (req.get('X-Forwarded-Proto') === 'https');
const secure = request.connection.encrypted || (request.get('X-Forwarded-Proto') === 'https');

if (options.ignoreFilter) {
ignoreRequest = ignoreRequest || options.ignoreFilter(req);
ignoreRequest = ignoreRequest || options.ignoreFilter(request);
}

if (ignoreRequest) {
Expand All @@ -26,13 +26,13 @@ module.exports = function (options) {
header += '; preload';
}

res.setHeader('Strict-Transport-Security', header);
response.setHeader('Strict-Transport-Security', header);
next();
} else {
res.writeHead(301, {
Location: 'https://' + req.get('host') + req.url
response.writeHead(301, {
Location: 'https://' + request.get('host') + request.url
});
res.end();
response.end();
}
};
};
12 changes: 7 additions & 5 deletions package.json
Expand Up @@ -23,11 +23,10 @@
},
"homepage": "https://github.com/JustinBeckwith/yes-https#readme",
"devDependencies": {
"express": "^4.16.3",
"mocha": "^6.0.0",
"request": "^2.87.0",
"supertest": "^4.0.0",
"xo": "^0.27.0"
"express": "^4.17.1",
"mocha": "^7.1.1",
"supertest": "^4.0.2",
"xo": "^0.29.0"
},
"xo": {
"overrides": [
Expand All @@ -36,5 +35,8 @@
"env": "mocha"
}
]
},
"engines": {
"node": ">=10"
}
}
16 changes: 8 additions & 8 deletions test/test.js
Expand Up @@ -11,8 +11,8 @@ describe('yes', () => {
// Configure a minimal web server with the defaults
const app = express();
app.use(yes());
app.get('/test', (req, res) => {
res.sendStatus(200);
app.get('/test', (request_, response) => {
response.sendStatus(200);
});

// Verify the request returns a 301
Expand All @@ -32,8 +32,8 @@ describe('yes', () => {
// Configure a minimal web server with the defaults
const app = express();
app.use(yes());
app.get('/test', (req, res) => {
res.sendStatus(200);
app.get('/test', (_request, response) => {
response.sendStatus(200);
});

// Verify the request returns the right header when using https
Expand All @@ -56,13 +56,13 @@ describe('yes', () => {
// Configure a minimal web server with the defaults
const app = express();
app.use(yes({
ignoreFilter: req => {
return (req.url.includes('/_ah/health'));
ignoreFilter: request_ => {
return (request_.url.includes('/_ah/health'));
}
}));

app.get('/_ah/health', (req, res) => {
res.sendStatus(200);
app.get('/_ah/health', (_request, response) => {
response.sendStatus(200);
});

// Verify the request returns a 200 for health checks
Expand Down

0 comments on commit 5ccbe34

Please sign in to comment.