From e6bf8d6d3fc0e57e6a492fdd12fe2e5e29ac28c6 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Tue, 3 Aug 2021 16:41:51 +0200 Subject: [PATCH] feat: add BYPASS cache state (#78) * chore: use @keyvhq/core instead of keyv * chore: add BYPASS cache state * ci: use github actions * chore: remove keyv dependency --- .github/workflows/main.yml | 40 ++++++++++++++++++++++++++++++++++++++ .travis.yml | 29 --------------------------- README.md | 1 - index.js | 7 +++++-- package.json | 5 +---- test/index.js | 4 ++-- 6 files changed, 48 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/main.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..bd3389d --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,40 @@ +name: test + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: lts/* + - name: Install + run: npm install --no-package-lock + - name: Test + run: npm test + - name: Report + run: mkdir -p coverage && npx nyc report --reporter=text-lcov > coverage/lcov.info + - name: Coverage + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Release + if: ${{ github.ref == 'refs/heads/master' && !startsWith(github.event.head_commit.message, 'chore(release):') && !startsWith(github.event.head_commit.message, 'docs:') }} + shell: 'script -q -e -c "bash {0}"' + env: + CONVENTIONAL_GITHUB_RELEASER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + git config --global user.email ${{ secrets.GIT_EMAIL }} + git config --global user.name ${{ secrets.GIT_USERNAME }} + npm run release diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a5e05a2..0000000 --- a/.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -language: node_js - -node_js: - - lts/* - - node - -after_success: npm run coverage - -stages: - - Test - - name: Release - if: branch = master AND commit_message !~ /(release|no-release)/ - -jobs: - include: - - stage: Release - node_js: lts/* - install: npm install --no-package-lock - before_deploy: - - git config user.email ${GITHUB_EMAIL:-"travis@travis-ci.org"} - - git config user.name ${GITHUB_USER:-"Travis CI"} - - git remote set-url origin https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git - - git checkout master - deploy: - skip_cleanup: true - provider: script - script: npm run release - on: - branch: master diff --git a/README.md b/README.md index c5c0d80..0e95616 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # cacheable-response ![Last version](https://img.shields.io/github/tag/Kikobeats/cacheable-response.svg?style=flat-square) -[![Build Status](https://img.shields.io/travis/Kikobeats/cacheable-response/master.svg?style=flat-square)](https://travis-ci.org/Kikobeats/cacheable-response) [![Coverage Status](https://img.shields.io/coveralls/Kikobeats/cacheable-response.svg?style=flat-square)](https://coveralls.io/github/Kikobeats/cacheable-response) [![NPM Status](https://img.shields.io/npm/dm/cacheable-response.svg?style=flat-square)](https://www.npmjs.org/package/cacheable-response) diff --git a/index.js b/index.js index 0e69962..0080480 100644 --- a/index.js +++ b/index.js @@ -5,10 +5,10 @@ const createCompress = require('compress-brotli') const normalizeUrl = require('normalize-url') const { parse } = require('querystring') const prettyMs = require('pretty-ms') +const Keyv = require('@keyvhq/core') const assert = require('assert') const getEtag = require('etag') const { URL } = require('url') -const Keyv = require('keyv') const isEmpty = value => value === undefined || @@ -42,7 +42,10 @@ const createSetHeaders = ({ revalidate }) => { } res.setHeader('Cache-Control', cacheControl) - res.setHeader('X-Cache-Status', isHit ? 'HIT' : 'MISS') + res.setHeader( + 'X-Cache-Status', + isHit ? 'HIT' : hasForce ? 'BYPASS' : 'MISS' + ) res.setHeader('X-Cache-Expired-At', prettyMs(diff)) res.setHeader('ETag', etag) } diff --git a/package.json b/package.json index 60c2d08..2cbab6d 100644 --- a/package.json +++ b/package.json @@ -54,10 +54,10 @@ "ssr" ], "dependencies": { + "@keyvhq/core": "~1.1.1", "compress-brotli": "~1.3.0", "debug-logfmt": "~1.0.4", "etag": "~1.8.1", - "keyv": "~4.0.3", "normalize-url": "~6.1.0", "pretty-ms": "~7.0.1" }, @@ -67,10 +67,8 @@ "ava": "latest", "ci-publish": "latest", "conventional-github-releaser": "latest", - "coveralls": "latest", "finepack": "latest", "git-authors-cli": "latest", - "git-dirty": "latest", "got": "latest", "lint-staged": "latest", "micro": "latest", @@ -93,7 +91,6 @@ "scripts": { "clean": "rm -rf node_modules", "contributors": "(git-authors-cli && finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true", - "coverage": "nyc report --reporter=text-lcov | coveralls", "lint": "standard-markdown README.md && standard", "postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)", "prerelease": "npm run update:check && npm run contributors", diff --git a/test/index.js b/test/index.js index e2a252b..9a14d91 100644 --- a/test/index.js +++ b/test/index.js @@ -1,8 +1,8 @@ const { AssertionError } = require('assert') const listen = require('test-listen') +const Keyv = require('@keyvhq/core') const micro = require('micro') -const Keyv = require('keyv') const test = require('ava') const got = require('got') @@ -193,7 +193,7 @@ test('force query params to invalidate', async t => { t.is(headersTwo['x-cache-status'], 'HIT') const { headers: headersThree } = await got(`${url}/kikobeats?force=true`) - t.is(headersThree['x-cache-status'], 'MISS') + t.is(headersThree['x-cache-status'], 'BYPASS') t.is(headersThree['x-cache-expired-at'], '0ms') // t.snapshot(parseCacheControl(headersThree))