From 2c861685356ca433cf738ec9e2314bc5ecf5e141 Mon Sep 17 00:00:00 2001 From: Glenn Hinks Date: Mon, 17 Aug 2020 15:17:22 -0400 Subject: [PATCH 01/12] docs: fastify session Session storage three examples all localhost - simple http - simple https - redis based storage over https --- package.json | 5 ++ servers/fastify/session/README.md | 48 ++++++++++++++ .../http-session-server.js | 26 ++++++++ .../https-session-server-redis/Dockerfile | 15 +++++ .../certificates/selfsigned.crt | 19 ++++++ .../certificates/selfsigned.key | 28 +++++++++ .../docker-compose.yml | 15 +++++ .../https-session-server-redis.js | 63 +++++++++++++++++++ .../https-session-server-redis/package.json | 20 ++++++ .../certificates/selfsigned.crt | 19 ++++++ .../certificates/selfsigned.key | 28 +++++++++ .../https-session-server.js | 45 +++++++++++++ 12 files changed, 331 insertions(+) create mode 100644 servers/fastify/session/README.md create mode 100644 servers/fastify/session/http-session-server/http-session-server.js create mode 100644 servers/fastify/session/https-session-server-redis/Dockerfile create mode 100644 servers/fastify/session/https-session-server-redis/certificates/selfsigned.crt create mode 100644 servers/fastify/session/https-session-server-redis/certificates/selfsigned.key create mode 100644 servers/fastify/session/https-session-server-redis/docker-compose.yml create mode 100644 servers/fastify/session/https-session-server-redis/https-session-server-redis.js create mode 100644 servers/fastify/session/https-session-server-redis/package.json create mode 100644 servers/fastify/session/https-session-server/certificates/selfsigned.crt create mode 100644 servers/fastify/session/https-session-server/certificates/selfsigned.key create mode 100644 servers/fastify/session/https-session-server/https-session-server.js diff --git a/package.json b/package.json index fb1abb6e..fcde8687 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,11 @@ "standard": "^14.3.3" }, "dependencies": { + "connect-redis": "^5.0.0", + "fastify-cookie": "^4.0.2", + "fastify-session": "^5.0.0", + "is-docker": "^2.1.1", + "redis": "^3.0.2", "yargs": "^15.3.1" }, "standard": { diff --git a/servers/fastify/session/README.md b/servers/fastify/session/README.md new file mode 100644 index 00000000..cf64f4e6 --- /dev/null +++ b/servers/fastify/session/README.md @@ -0,0 +1,48 @@ +# Fastify Session + +A common use case for a web framework is to provide session storage. Fastify has a [concept of plugins](https://www.fastify.io/docs/latest/Plugins-Guide/) +and the plugin for session is [fastify-session](https://github.com/SerayaEryn/fastify-session). These examples +will demonstrate server side session storage. + +## Simple local http session demonstration using local storage + +[http-session-server](./http-session-server/http-session-server.js) + +The most simple demonstration is an http server using a memory store. A memory store would be a local nodeJS based +storage mechanism. This demonstrates the concept of +session in fastify but is not what you would want in production. You would want to use an https server and +you would want to use a network based storage mechanism. In order to scale your NodeJS based servers you +would need to share the session storage between multiple instances of the same program so that any particular +cookied request would find its own session. + +In this example in adddition to requiring fastify there are two additional modules being required. These are + +- [fastify-session](https://www.npmjs.com/package/fastify-session) +- [fastify-cookie](https://www.npmjs.com/package/fastify-cookie) + +The fastify cookie plugin will add support to read and set cookie headers. The fastify session plugin provides session +based storage on the localhost. + + +## Simple local https session demonstration using local storage + +[https-session-server](./https-session-server/https-session-server.js) + +Another simple demonstration is the use of https on your local machine using local nodeJS based storage. In order to +start **fastify** as an https server it is necessary to provide certificates. Localhost certificates have been provided +to save the user the difficulty of creating one. This is a command to create certificates. + +```shell script +penssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout selfsigned.key -out selfsigned.crt -subj "/CN=localhost" +``` + +The key and cert are created using [openssl](https://www.openssl.org/) and were created on a linux ubuntu system. The +commands are similar for osx. + +## Local https session using redis + +[https-session-server-redis](./https-session-server-redis/https-session-server-redis.js) + +A more realistic example of creating a session on fastify would involve using a network based store. This would allow +multiple instances fastify to access the session data when a cookie is sent. + diff --git a/servers/fastify/session/http-session-server/http-session-server.js b/servers/fastify/session/http-session-server/http-session-server.js new file mode 100644 index 00000000..67f96fe1 --- /dev/null +++ b/servers/fastify/session/http-session-server/http-session-server.js @@ -0,0 +1,26 @@ +/* These examples are based on those from the fastify-session plugin readme */ + +const Fastify = require('fastify') +const fastifySession = require('fastify-session') +const fastifyCookie = require('fastify-cookie') + +const fastify = Fastify({ logger: true }) +fastify.register(fastifyCookie) +const sessionOptions = { + secret: 'a secret with minimum length of 32 characters', + cookieName: 'example-name', + cookie: { + secure: false, + maxAge: 1000 * 60 * 3 + } +} +fastify.register(fastifySession, sessionOptions) + +fastify.get('/', (request, reply) => { + if (request.session) { + request.session.count = request.session.count ? request.session.count + 1 : 1 + } + return { hello: `route requested ${request.session.count} times in this session` } +}) + +fastify.listen(3000, fastify.log.info('listening...')) diff --git a/servers/fastify/session/https-session-server-redis/Dockerfile b/servers/fastify/session/https-session-server-redis/Dockerfile new file mode 100644 index 00000000..beff4495 --- /dev/null +++ b/servers/fastify/session/https-session-server-redis/Dockerfile @@ -0,0 +1,15 @@ +FROM node:12-alpine + +USER node + +RUN mkdir /home/node/code + +WORKDIR /home/node/code + +COPY --chown=node:node package.json package-lock.json ./ + +RUN npm ci + +COPY --chown=node:node . . + +CMD ["node", "https-session-server-redis.js"] diff --git a/servers/fastify/session/https-session-server-redis/certificates/selfsigned.crt b/servers/fastify/session/https-session-server-redis/certificates/selfsigned.crt new file mode 100644 index 00000000..444a6da8 --- /dev/null +++ b/servers/fastify/session/https-session-server-redis/certificates/selfsigned.crt @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIDCTCCAfGgAwIBAgIUGSuVcr1tSWFodB3chT1HG3ExSdEwDQYJKoZIhvcNAQEL +BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTIwMDgxNjEzMzAwN1oXDTIxMDgx +NjEzMzAwN1owFDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEF +AAOCAQ8AMIIBCgKCAQEAx+TCGDTi5hULfciEG18Ec6M9aL+CbjQxFVKpLpoE2uKG +kJesSjze489PFV/355ai+afx/FV6yUSFTd5ZiBSFRPWecZ2/QVZdbkrdUjCF4EKN ++z40arZpb5l82R6RXgIfcZkcTjqrfX4TXoWrC5PhmdOtgG/BWCtwDSOBYfCb3uRP +iWyD2+9OLblbjOezuxrOYR6N6R+bIFtacp0Agunyd88RYeuYTTjWMmridf29Nip4 +Tyg6fFmFcJ0BhzyrQQM95eSDoABJv7V001WUiXGI/Y47XdhUxL4J1F5ZEbp3GglP +lj5kzip4hIN4AOdRJOPiRDtJSUdHcBqc1qi1IJcj4QIDAQABo1MwUTAdBgNVHQ4E +FgQU9TlVrEOHqghi+3yxCL2dDOBwH8kwHwYDVR0jBBgwFoAU9TlVrEOHqghi+3yx +CL2dDOBwH8kwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEANDOt +uiMWeQhm8b/aBPlmC6ABDsQRGsZX9j3mlKcdoQmLfXJc6ZtfK+gi54hYQWDcprp+ +Xa2odGLi1kKmn1Sv1kjHhA7sUrSZKV+1mAujDkO9lwygIRoqPqeW9DX4g8mfxWXd +X5zQ5ZaO8gAG1qgdGAut3JU0GLCduDBRJ6UJvzYrVGGY6Uhocp1u6u2drhC8QtJk +x4/piT/JFFzdGTAwpUCsYkElTW5sIEM4Nx1+g37My/KQqajWI38paa2TpMOiI5rU +MtVgL8QAKlly1TA8lmXtfwsod3Y4gnyd6F7Jr4Vzx2OcCPZn0uyz7lQRqbHT3hNU +ieLvVoq75jbffPxewQ== +-----END CERTIFICATE----- diff --git a/servers/fastify/session/https-session-server-redis/certificates/selfsigned.key b/servers/fastify/session/https-session-server-redis/certificates/selfsigned.key new file mode 100644 index 00000000..b0473b89 --- /dev/null +++ b/servers/fastify/session/https-session-server-redis/certificates/selfsigned.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDH5MIYNOLmFQt9 +yIQbXwRzoz1ov4JuNDEVUqkumgTa4oaQl6xKPN7jz08VX/fnlqL5p/H8VXrJRIVN +3lmIFIVE9Z5xnb9BVl1uSt1SMIXgQo37PjRqtmlvmXzZHpFeAh9xmRxOOqt9fhNe +hasLk+GZ062Ab8FYK3ANI4Fh8Jve5E+JbIPb704tuVuM57O7Gs5hHo3pH5sgW1py +nQCC6fJ3zxFh65hNONYyauJ1/b02KnhPKDp8WYVwnQGHPKtBAz3l5IOgAEm/tXTT +VZSJcYj9jjtd2FTEvgnUXlkRuncaCU+WPmTOKniEg3gA51Ek4+JEO0lJR0dwGpzW +qLUglyPhAgMBAAECggEAF/br8hz9CtqBCy5r8CAfF4H9jb5P88hcDhNf5w9d/6Pi +wBj+9dOAYU1sTMK5pNEhbs7cqwTQeKq3VJOQpkjXhWHxAewIjtu8zck56W2Zzz4L +aZCWliiSUWfUWO9aPCwC+wqBIzvTbXMc/VsHG5c6F8gR5/D9/AURJPIZw9Ulyr3c +IhAodL3SbqZUr7WT3ZzHeQ5WsDqq8Y8lOSIgemRO5RAkv3r7FQgUyoWu6P3fQTSd +Eb6ZLQ6xRnxNvKDGea1Bv5DI1Nuni9Cv7XoVDatUukYXMQqYrQWNXS20/OVzJxF2 +tNsCbG0pZcEp0cf2tWTQHyYN/iMWEA63Aox0BGFkVQKBgQDtKq0EncX9zyiGreOD +WV6PSQamN4rfQlzkN77U+WNut3JDwUv5CdavpTt2Qr0g/wLsmovKpMUnwhERyO4X +JBL41/eAOtHeQzwYxE7aoVGFPS4/3QIGV8Bqd0rHgYJHztfa26WJWJcnIpwWBZgY +Oao1xlveI+3zPO++ajw8OA2HywKBgQDXxFzzb1oNM6E9+w+r/kXW1fUM2gln5RgU +Jdc+H/ckiJSGes3e7ci5zek53vgCMiQdmQ6kDON/bnArRg+ol7fCC9sUeuXg1TA4 +cNaeBjf7fQhzb1CQlJp+h38Vy7NgkvPAkgI4PWJihgT7QEsiMn+k3mBHAXkfcbuh +WwJ2mbUVgwKBgBcaQSBh/hdrRpdX+QGigwOSKYOnhW+aF1Jj28MDSBxQ4mCXQ79O +pgsWHWS3u5SrQq2poFRtGId28BK7b/XxHaf/4awsDqWIByKifMvvSvGftBGkhb34 +blXwqOgmRXqZO42mN8nZR2AYjvvWL6qsc1gpqmlJNrSrCu+RiayUCT1hAoGBAKaW +NgnBdC5zKU+4Uh5BwFwhbwRQJyju6QtNOAUAGwk65il6EQ7IWcyS3TnQG31ehyHO +9U3VoaPWeYX/nsFU+gw4qRoD1Q4kqwk4nYr+VCS4IVk2nWYzRaDhLk5+qmyqqMWK +NWqEgjx9KsVtm1S41nJNOto3mfOcFPh8UseM3xHPAoGBAKzHshWR+jmRrVp0XKrz +Yl/Vz1pCIg1bbQk9iip08FqJTpMMd3sr/XS/ULX5jaOeEQcT4JQRr8H84rhunoBu +AMCPCbqLNjpyxxY6zWftYOx4chLECh6/ro/EOOiJnxrQB5AHcHOoHi0mjl+Lux/q +1jbqcR5IfkapWhD2xuyLgVOz +-----END PRIVATE KEY----- diff --git a/servers/fastify/session/https-session-server-redis/docker-compose.yml b/servers/fastify/session/https-session-server-redis/docker-compose.yml new file mode 100644 index 00000000..ca951874 --- /dev/null +++ b/servers/fastify/session/https-session-server-redis/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3" +services: + fastify-session-with-redis: + build: . + ports: + - "3000:3000" + volumes: + - .:/home/node/code + - /home/node/code/node_modules + depends_on: + - redis + redis: + image: redis:6.0.5 + ports: + - "6379:6379" diff --git a/servers/fastify/session/https-session-server-redis/https-session-server-redis.js b/servers/fastify/session/https-session-server-redis/https-session-server-redis.js new file mode 100644 index 00000000..c33848c4 --- /dev/null +++ b/servers/fastify/session/https-session-server-redis/https-session-server-redis.js @@ -0,0 +1,63 @@ +const path = require('path') +const Fastify = require('fastify') +const fastifySession = require('fastify-session') +const fastifyCookie = require('fastify-cookie') +const fs = require('fs') +const isDocker = require('is-docker') +const redis = require('redis') +const RedisStore = require('connect-redis')(fastifySession) + +const APP_PORT = 3000 +const REDIS_PORT = 6379 + +// the docker compose service is called redis +let host = 'localhost' +if (isDocker()) { + host = 'redis' +} + +const redisClient = redis.createClient({ + host, + port: REDIS_PORT +}) + +const getCertificates = () => { + const cert = fs.readFileSync(path.join(__dirname, './certificates/selfsigned.crt'), 'utf-8') + const key = fs.readFileSync(path.join(__dirname, './certificates/selfsigned.key'), 'utf-8') + return { + cert, + key + } +} +const { key, cert } = getCertificates() + +const fastify = Fastify({ + https: { + allowHTTP1: true, + key, + cert + }, + logger: true +}) + +fastify.register(fastifyCookie) + +const sessionOptions = { + secret: 'a secret with minimum length of 32 characters', + cookieName: 'example-redis-session', + cookie: { + secure: true, + maxAge: 1000 * 60 * 3 + }, + store: new RedisStore({ client: redisClient }) +} +fastify.register(fastifySession, sessionOptions) + +fastify.get('/', (request, reply) => { + if (request.session) { + request.session.count = request.session.count ? request.session.count + 1 : 1 + } + return { hello: `route requested ${request.session.count} times in this session` } +}) + +fastify.listen(APP_PORT, '0.0.0.0', fastify.log.info('listening...')) diff --git a/servers/fastify/session/https-session-server-redis/package.json b/servers/fastify/session/https-session-server-redis/package.json new file mode 100644 index 00000000..bbbdcf03 --- /dev/null +++ b/servers/fastify/session/https-session-server-redis/package.json @@ -0,0 +1,20 @@ +{ + "name": "https-session-server-redis", + "version": "1.0.0", + "description": "", + "main": "https-session-server-redis.js", + "scripts": { + "start": "node https-session-server-redis.js" + }, + "keywords": [], + "author": "", + "license": "MIT", + "dependencies": { + "connect-redis": "^5.0.0", + "fastify": "^3.2.0", + "fastify-cookie": "^4.0.2", + "fastify-session": "^5.0.0", + "is-docker": "^2.1.1", + "redis": "^3.0.2" + } +} diff --git a/servers/fastify/session/https-session-server/certificates/selfsigned.crt b/servers/fastify/session/https-session-server/certificates/selfsigned.crt new file mode 100644 index 00000000..444a6da8 --- /dev/null +++ b/servers/fastify/session/https-session-server/certificates/selfsigned.crt @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIDCTCCAfGgAwIBAgIUGSuVcr1tSWFodB3chT1HG3ExSdEwDQYJKoZIhvcNAQEL +BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTIwMDgxNjEzMzAwN1oXDTIxMDgx +NjEzMzAwN1owFDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEF +AAOCAQ8AMIIBCgKCAQEAx+TCGDTi5hULfciEG18Ec6M9aL+CbjQxFVKpLpoE2uKG +kJesSjze489PFV/355ai+afx/FV6yUSFTd5ZiBSFRPWecZ2/QVZdbkrdUjCF4EKN ++z40arZpb5l82R6RXgIfcZkcTjqrfX4TXoWrC5PhmdOtgG/BWCtwDSOBYfCb3uRP +iWyD2+9OLblbjOezuxrOYR6N6R+bIFtacp0Agunyd88RYeuYTTjWMmridf29Nip4 +Tyg6fFmFcJ0BhzyrQQM95eSDoABJv7V001WUiXGI/Y47XdhUxL4J1F5ZEbp3GglP +lj5kzip4hIN4AOdRJOPiRDtJSUdHcBqc1qi1IJcj4QIDAQABo1MwUTAdBgNVHQ4E +FgQU9TlVrEOHqghi+3yxCL2dDOBwH8kwHwYDVR0jBBgwFoAU9TlVrEOHqghi+3yx +CL2dDOBwH8kwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEANDOt +uiMWeQhm8b/aBPlmC6ABDsQRGsZX9j3mlKcdoQmLfXJc6ZtfK+gi54hYQWDcprp+ +Xa2odGLi1kKmn1Sv1kjHhA7sUrSZKV+1mAujDkO9lwygIRoqPqeW9DX4g8mfxWXd +X5zQ5ZaO8gAG1qgdGAut3JU0GLCduDBRJ6UJvzYrVGGY6Uhocp1u6u2drhC8QtJk +x4/piT/JFFzdGTAwpUCsYkElTW5sIEM4Nx1+g37My/KQqajWI38paa2TpMOiI5rU +MtVgL8QAKlly1TA8lmXtfwsod3Y4gnyd6F7Jr4Vzx2OcCPZn0uyz7lQRqbHT3hNU +ieLvVoq75jbffPxewQ== +-----END CERTIFICATE----- diff --git a/servers/fastify/session/https-session-server/certificates/selfsigned.key b/servers/fastify/session/https-session-server/certificates/selfsigned.key new file mode 100644 index 00000000..b0473b89 --- /dev/null +++ b/servers/fastify/session/https-session-server/certificates/selfsigned.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDH5MIYNOLmFQt9 +yIQbXwRzoz1ov4JuNDEVUqkumgTa4oaQl6xKPN7jz08VX/fnlqL5p/H8VXrJRIVN +3lmIFIVE9Z5xnb9BVl1uSt1SMIXgQo37PjRqtmlvmXzZHpFeAh9xmRxOOqt9fhNe +hasLk+GZ062Ab8FYK3ANI4Fh8Jve5E+JbIPb704tuVuM57O7Gs5hHo3pH5sgW1py +nQCC6fJ3zxFh65hNONYyauJ1/b02KnhPKDp8WYVwnQGHPKtBAz3l5IOgAEm/tXTT +VZSJcYj9jjtd2FTEvgnUXlkRuncaCU+WPmTOKniEg3gA51Ek4+JEO0lJR0dwGpzW +qLUglyPhAgMBAAECggEAF/br8hz9CtqBCy5r8CAfF4H9jb5P88hcDhNf5w9d/6Pi +wBj+9dOAYU1sTMK5pNEhbs7cqwTQeKq3VJOQpkjXhWHxAewIjtu8zck56W2Zzz4L +aZCWliiSUWfUWO9aPCwC+wqBIzvTbXMc/VsHG5c6F8gR5/D9/AURJPIZw9Ulyr3c +IhAodL3SbqZUr7WT3ZzHeQ5WsDqq8Y8lOSIgemRO5RAkv3r7FQgUyoWu6P3fQTSd +Eb6ZLQ6xRnxNvKDGea1Bv5DI1Nuni9Cv7XoVDatUukYXMQqYrQWNXS20/OVzJxF2 +tNsCbG0pZcEp0cf2tWTQHyYN/iMWEA63Aox0BGFkVQKBgQDtKq0EncX9zyiGreOD +WV6PSQamN4rfQlzkN77U+WNut3JDwUv5CdavpTt2Qr0g/wLsmovKpMUnwhERyO4X +JBL41/eAOtHeQzwYxE7aoVGFPS4/3QIGV8Bqd0rHgYJHztfa26WJWJcnIpwWBZgY +Oao1xlveI+3zPO++ajw8OA2HywKBgQDXxFzzb1oNM6E9+w+r/kXW1fUM2gln5RgU +Jdc+H/ckiJSGes3e7ci5zek53vgCMiQdmQ6kDON/bnArRg+ol7fCC9sUeuXg1TA4 +cNaeBjf7fQhzb1CQlJp+h38Vy7NgkvPAkgI4PWJihgT7QEsiMn+k3mBHAXkfcbuh +WwJ2mbUVgwKBgBcaQSBh/hdrRpdX+QGigwOSKYOnhW+aF1Jj28MDSBxQ4mCXQ79O +pgsWHWS3u5SrQq2poFRtGId28BK7b/XxHaf/4awsDqWIByKifMvvSvGftBGkhb34 +blXwqOgmRXqZO42mN8nZR2AYjvvWL6qsc1gpqmlJNrSrCu+RiayUCT1hAoGBAKaW +NgnBdC5zKU+4Uh5BwFwhbwRQJyju6QtNOAUAGwk65il6EQ7IWcyS3TnQG31ehyHO +9U3VoaPWeYX/nsFU+gw4qRoD1Q4kqwk4nYr+VCS4IVk2nWYzRaDhLk5+qmyqqMWK +NWqEgjx9KsVtm1S41nJNOto3mfOcFPh8UseM3xHPAoGBAKzHshWR+jmRrVp0XKrz +Yl/Vz1pCIg1bbQk9iip08FqJTpMMd3sr/XS/ULX5jaOeEQcT4JQRr8H84rhunoBu +AMCPCbqLNjpyxxY6zWftYOx4chLECh6/ro/EOOiJnxrQB5AHcHOoHi0mjl+Lux/q +1jbqcR5IfkapWhD2xuyLgVOz +-----END PRIVATE KEY----- diff --git a/servers/fastify/session/https-session-server/https-session-server.js b/servers/fastify/session/https-session-server/https-session-server.js new file mode 100644 index 00000000..e5f6e800 --- /dev/null +++ b/servers/fastify/session/https-session-server/https-session-server.js @@ -0,0 +1,45 @@ +const path = require('path') +const Fastify = require('fastify') +const fastifySession = require('fastify-session') +const fastifyCookie = require('fastify-cookie') +const fs = require('fs') + +const APP_PORT = 3000 +const getCertificates = () => { + const cert = fs.readFileSync(path.join(__dirname, './certificates/selfsigned.crt'), 'utf-8') + const key = fs.readFileSync(path.join(__dirname, './certificates/selfsigned.key'), 'utf-8') + return { + cert, + key + } +} +const { key, cert } = getCertificates() + +const fastify = Fastify({ + https: { + allowHTTP1: true, + key, + cert + } +}) + +fastify.register(fastifyCookie) + +const sessionOptions = { + secret: 'a secret with minimum length of 32 characters', + cookieName: 'example-using-https-connection', + cookie: { + secure: true, + maxAge: 1000 * 60 * 3 + } +} +fastify.register(fastifySession, sessionOptions) + +fastify.get('/', (request, reply) => { + if (request.session) { + request.session.count = request.session.count ? request.session.count + 1 : 1 + } + return { hello: `route requested ${request.session.count} times in this session` } +}) + +fastify.listen(APP_PORT, fastify.log.info('listening...')) From 904ac4469cd8c92548643dab03512ff8f5aa20b0 Mon Sep 17 00:00:00 2001 From: Glenn Hinks Date: Wed, 19 Aug 2020 14:22:48 -0400 Subject: [PATCH 02/12] feature: fastify/hello-world update the docs with docker instructions. --- servers/fastify/session/README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/servers/fastify/session/README.md b/servers/fastify/session/README.md index cf64f4e6..66176824 100644 --- a/servers/fastify/session/README.md +++ b/servers/fastify/session/README.md @@ -45,4 +45,20 @@ commands are similar for osx. A more realistic example of creating a session on fastify would involve using a network based store. This would allow multiple instances fastify to access the session data when a cookie is sent. +In order to run this you either have to have a local [redis](https://redislabs.com/get-started-with-redis/) running or +use docker. If you have [docker](https://www.docker.com/products/docker-desktop) installed then can simple bring the +service up +```shell script +docker-compose up +``` + +The server will be running on port 3000 and the session will be stored in the redis cache. + +Each time you hit the url the response will tell you how many times you requested this URL. + +```json +{ +"hello": "route requested 6 times in this session" +} +``` From ccd97fda684a0a00a3935a128a7cdf16fbb0156d Mon Sep 17 00:00:00 2001 From: Glenn Hinks Date: Wed, 19 Aug 2020 14:51:30 -0400 Subject: [PATCH 03/12] feature: fastify/session markdown lint corrections A markdownlintignore file has been added as there will be multiple folders which contain node module readmes that do not comply. --- .markdownlintignore | 2 ++ package.json | 2 +- servers/fastify/session/README.md | 11 +++++------ 3 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 .markdownlintignore diff --git a/.markdownlintignore b/.markdownlintignore new file mode 100644 index 00000000..6db0d6c1 --- /dev/null +++ b/.markdownlintignore @@ -0,0 +1,2 @@ +node_modules +/servers/fastify/session/node_modules diff --git a/package.json b/package.json index aadf0c5c..31b55bba 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "test:unit": "jest --coverage", "test:onlychanged": "jest --onlyChanged --coverage", - "test:markdown": "markdownlint . --ignore ./node_modules", + "test:markdown": "markdownlint . ", "lint": "standard", "test": "npm run lint && npm run test:unit && npm run test:markdown" }, diff --git a/servers/fastify/session/README.md b/servers/fastify/session/README.md index 66176824..1eb4b577 100644 --- a/servers/fastify/session/README.md +++ b/servers/fastify/session/README.md @@ -2,9 +2,9 @@ A common use case for a web framework is to provide session storage. Fastify has a [concept of plugins](https://www.fastify.io/docs/latest/Plugins-Guide/) and the plugin for session is [fastify-session](https://github.com/SerayaEryn/fastify-session). These examples -will demonstrate server side session storage. +will demonstrate server side session storage. -## Simple local http session demonstration using local storage +## Simple local http session demonstration using local storage [http-session-server](./http-session-server/http-session-server.js) @@ -15,7 +15,7 @@ you would want to use a network based storage mechanism. In order to scale your would need to share the session storage between multiple instances of the same program so that any particular cookied request would find its own session. -In this example in adddition to requiring fastify there are two additional modules being required. These are +In this example in addition to requiring fastify there are two additional modules being required. These are - [fastify-session](https://www.npmjs.com/package/fastify-session) - [fastify-cookie](https://www.npmjs.com/package/fastify-cookie) @@ -23,7 +23,6 @@ In this example in adddition to requiring fastify there are two additional modul The fastify cookie plugin will add support to read and set cookie headers. The fastify session plugin provides session based storage on the localhost. - ## Simple local https session demonstration using local storage [https-session-server](./https-session-server/https-session-server.js) @@ -45,12 +44,12 @@ commands are similar for osx. A more realistic example of creating a session on fastify would involve using a network based store. This would allow multiple instances fastify to access the session data when a cookie is sent. -In order to run this you either have to have a local [redis](https://redislabs.com/get-started-with-redis/) running or +In order to run this you either have to have a local [redis](https://redislabs.com/get-started-with-redis/) running or use docker. If you have [docker](https://www.docker.com/products/docker-desktop) installed then can simple bring the service up ```shell script -docker-compose up +docker-compose up ``` The server will be running on port 3000 and the session will be stored in the redis cache. From 2642eb90ac0cfb909beacace63b2e71a2ce269a9 Mon Sep 17 00:00:00 2001 From: Glenn Hinks Date: Thu, 20 Aug 2020 16:14:30 -0400 Subject: [PATCH 04/12] feature: fastify/example-session take feedback and update as suggested. --- servers/fastify/session/README.md | 2 +- .../http-session-server/http-session-server.js | 2 ++ .../https-session-server-redis.js | 15 ++++----------- .../https-session-server-redis/package.json | 4 ++-- .../https-session-server/https-session-server.js | 3 ++- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/servers/fastify/session/README.md b/servers/fastify/session/README.md index 1eb4b577..db520f9b 100644 --- a/servers/fastify/session/README.md +++ b/servers/fastify/session/README.md @@ -43,7 +43,7 @@ commands are similar for osx. [https-session-server-redis](./https-session-server-redis/https-session-server-redis.js) A more realistic example of creating a session on fastify would involve using a network based store. This would allow -multiple instances fastify to access the session data when a cookie is sent. +multiple instances of fastify to access the session data when a cookie is sent. In order to run this you either have to have a local [redis](https://redislabs.com/get-started-with-redis/) running or use docker. If you have [docker](https://www.docker.com/products/docker-desktop) installed then can simple bring the service up diff --git a/servers/fastify/session/http-session-server/http-session-server.js b/servers/fastify/session/http-session-server/http-session-server.js index 67f96fe1..6a7b1272 100644 --- a/servers/fastify/session/http-session-server/http-session-server.js +++ b/servers/fastify/session/http-session-server/http-session-server.js @@ -1,3 +1,5 @@ +'use strict' + /* These examples are based on those from the fastify-session plugin readme */ const Fastify = require('fastify') diff --git a/servers/fastify/session/https-session-server-redis/https-session-server-redis.js b/servers/fastify/session/https-session-server-redis/https-session-server-redis.js index c33848c4..b242a601 100644 --- a/servers/fastify/session/https-session-server-redis/https-session-server-redis.js +++ b/servers/fastify/session/https-session-server-redis/https-session-server-redis.js @@ -1,14 +1,13 @@ +'use strict' + const path = require('path') const Fastify = require('fastify') const fastifySession = require('fastify-session') const fastifyCookie = require('fastify-cookie') const fs = require('fs') const isDocker = require('is-docker') -const redis = require('redis') -const RedisStore = require('connect-redis')(fastifySession) const APP_PORT = 3000 -const REDIS_PORT = 6379 // the docker compose service is called redis let host = 'localhost' @@ -16,11 +15,6 @@ if (isDocker()) { host = 'redis' } -const redisClient = redis.createClient({ - host, - port: REDIS_PORT -}) - const getCertificates = () => { const cert = fs.readFileSync(path.join(__dirname, './certificates/selfsigned.crt'), 'utf-8') const key = fs.readFileSync(path.join(__dirname, './certificates/selfsigned.key'), 'utf-8') @@ -33,7 +27,6 @@ const { key, cert } = getCertificates() const fastify = Fastify({ https: { - allowHTTP1: true, key, cert }, @@ -41,6 +34,7 @@ const fastify = Fastify({ }) fastify.register(fastifyCookie) +fastify.register(require('fastify-redis'), { host: '127.0.0.1' }) const sessionOptions = { secret: 'a secret with minimum length of 32 characters', @@ -48,8 +42,7 @@ const sessionOptions = { cookie: { secure: true, maxAge: 1000 * 60 * 3 - }, - store: new RedisStore({ client: redisClient }) + } } fastify.register(fastifySession, sessionOptions) diff --git a/servers/fastify/session/https-session-server-redis/package.json b/servers/fastify/session/https-session-server-redis/package.json index bbbdcf03..d6583684 100644 --- a/servers/fastify/session/https-session-server-redis/package.json +++ b/servers/fastify/session/https-session-server-redis/package.json @@ -13,8 +13,8 @@ "connect-redis": "^5.0.0", "fastify": "^3.2.0", "fastify-cookie": "^4.0.2", + "fastify-redis": "^4.0.3", "fastify-session": "^5.0.0", - "is-docker": "^2.1.1", - "redis": "^3.0.2" + "is-docker": "^2.1.1" } } diff --git a/servers/fastify/session/https-session-server/https-session-server.js b/servers/fastify/session/https-session-server/https-session-server.js index e5f6e800..39e7bcb3 100644 --- a/servers/fastify/session/https-session-server/https-session-server.js +++ b/servers/fastify/session/https-session-server/https-session-server.js @@ -1,3 +1,5 @@ +'use strict' + const path = require('path') const Fastify = require('fastify') const fastifySession = require('fastify-session') @@ -17,7 +19,6 @@ const { key, cert } = getCertificates() const fastify = Fastify({ https: { - allowHTTP1: true, key, cert } From 362619f3c710265a4676163b897e8f215cd554c3 Mon Sep 17 00:00:00 2001 From: Glenn Hinks Date: Thu, 20 Aug 2020 16:27:25 -0400 Subject: [PATCH 05/12] feature: fastify/example-session alter the host name to take account of whether it is inside a docker container or not --- .../https-session-server-redis.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/servers/fastify/session/https-session-server-redis/https-session-server-redis.js b/servers/fastify/session/https-session-server-redis/https-session-server-redis.js index b242a601..f44e23f7 100644 --- a/servers/fastify/session/https-session-server-redis/https-session-server-redis.js +++ b/servers/fastify/session/https-session-server-redis/https-session-server-redis.js @@ -34,7 +34,7 @@ const fastify = Fastify({ }) fastify.register(fastifyCookie) -fastify.register(require('fastify-redis'), { host: '127.0.0.1' }) +fastify.register(require('fastify-redis'), { host }) const sessionOptions = { secret: 'a secret with minimum length of 32 characters', @@ -53,4 +53,9 @@ fastify.get('/', (request, reply) => { return { hello: `route requested ${request.session.count} times in this session` } }) -fastify.listen(APP_PORT, '0.0.0.0', fastify.log.info('listening...')) +fastify.listen(APP_PORT, '0.0.0.0', (err) => { + if (err) { + fastify.log.error(err) + process.exit(1) + } +}) From b8333fc2667621a37fd6a1aafb4d1011ee75e2c3 Mon Sep 17 00:00:00 2001 From: Glenn Date: Fri, 21 Aug 2020 17:00:41 -0400 Subject: [PATCH 06/12] Update servers/fastify/session/https-session-server/https-session-server.js Co-authored-by: Matteo Collina --- .../session/https-session-server/https-session-server.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/servers/fastify/session/https-session-server/https-session-server.js b/servers/fastify/session/https-session-server/https-session-server.js index 39e7bcb3..50d02905 100644 --- a/servers/fastify/session/https-session-server/https-session-server.js +++ b/servers/fastify/session/https-session-server/https-session-server.js @@ -43,4 +43,9 @@ fastify.get('/', (request, reply) => { return { hello: `route requested ${request.session.count} times in this session` } }) -fastify.listen(APP_PORT, fastify.log.info('listening...')) +fastify.listen(APP_PORT, function (err) { + if (err) { + fastify.log.error(err) + process.exit(1) + } +}) From d6cbe4bfcf4832618fe2d0c04b2e606dc120f454 Mon Sep 17 00:00:00 2001 From: Glenn Hinks Date: Mon, 24 Aug 2020 10:33:09 -0400 Subject: [PATCH 07/12] feature: fastify/session add logging to examples where it was missing use async in all route handlers use consistent listen handler across examples --- .../session/http-session-server/http-session-server.js | 10 ++++++++-- .../https-session-server-redis.js | 2 +- .../https-session-server/https-session-server.js | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/servers/fastify/session/http-session-server/http-session-server.js b/servers/fastify/session/http-session-server/http-session-server.js index 6a7b1272..35007110 100644 --- a/servers/fastify/session/http-session-server/http-session-server.js +++ b/servers/fastify/session/http-session-server/http-session-server.js @@ -6,6 +6,7 @@ const Fastify = require('fastify') const fastifySession = require('fastify-session') const fastifyCookie = require('fastify-cookie') +const APP_PORT = 3000 const fastify = Fastify({ logger: true }) fastify.register(fastifyCookie) const sessionOptions = { @@ -18,11 +19,16 @@ const sessionOptions = { } fastify.register(fastifySession, sessionOptions) -fastify.get('/', (request, reply) => { +fastify.get('/', async (request, reply) => { if (request.session) { request.session.count = request.session.count ? request.session.count + 1 : 1 } return { hello: `route requested ${request.session.count} times in this session` } }) -fastify.listen(3000, fastify.log.info('listening...')) +fastify.listen(APP_PORT, function (err) { + if (err) { + fastify.log.error(err) + process.exit(1) + } +}) diff --git a/servers/fastify/session/https-session-server-redis/https-session-server-redis.js b/servers/fastify/session/https-session-server-redis/https-session-server-redis.js index f44e23f7..9137c229 100644 --- a/servers/fastify/session/https-session-server-redis/https-session-server-redis.js +++ b/servers/fastify/session/https-session-server-redis/https-session-server-redis.js @@ -46,7 +46,7 @@ const sessionOptions = { } fastify.register(fastifySession, sessionOptions) -fastify.get('/', (request, reply) => { +fastify.get('/', async (request, reply) => { if (request.session) { request.session.count = request.session.count ? request.session.count + 1 : 1 } diff --git a/servers/fastify/session/https-session-server/https-session-server.js b/servers/fastify/session/https-session-server/https-session-server.js index 50d02905..1c56b6c7 100644 --- a/servers/fastify/session/https-session-server/https-session-server.js +++ b/servers/fastify/session/https-session-server/https-session-server.js @@ -18,6 +18,7 @@ const getCertificates = () => { const { key, cert } = getCertificates() const fastify = Fastify({ + logger: true, https: { key, cert @@ -36,7 +37,7 @@ const sessionOptions = { } fastify.register(fastifySession, sessionOptions) -fastify.get('/', (request, reply) => { +fastify.get('/', async (request, reply) => { if (request.session) { request.session.count = request.session.count ? request.session.count + 1 : 1 } From a32cb9803d12f3713cca3ece6618e4bb242dbaaf Mon Sep 17 00:00:00 2001 From: Glenn Hinks Date: Mon, 24 Aug 2020 10:44:24 -0400 Subject: [PATCH 08/12] feature: fastify/session use PORT from the environment first to decide where to listen. --- .../fastify/session/http-session-server/http-session-server.js | 2 +- .../https-session-server-redis/https-session-server-redis.js | 2 +- .../session/https-session-server/https-session-server.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/servers/fastify/session/http-session-server/http-session-server.js b/servers/fastify/session/http-session-server/http-session-server.js index 35007110..29085cc8 100644 --- a/servers/fastify/session/http-session-server/http-session-server.js +++ b/servers/fastify/session/http-session-server/http-session-server.js @@ -6,7 +6,7 @@ const Fastify = require('fastify') const fastifySession = require('fastify-session') const fastifyCookie = require('fastify-cookie') -const APP_PORT = 3000 +const APP_PORT = process.env.PORT || 3000 const fastify = Fastify({ logger: true }) fastify.register(fastifyCookie) const sessionOptions = { diff --git a/servers/fastify/session/https-session-server-redis/https-session-server-redis.js b/servers/fastify/session/https-session-server-redis/https-session-server-redis.js index 9137c229..d0aba9df 100644 --- a/servers/fastify/session/https-session-server-redis/https-session-server-redis.js +++ b/servers/fastify/session/https-session-server-redis/https-session-server-redis.js @@ -7,7 +7,7 @@ const fastifyCookie = require('fastify-cookie') const fs = require('fs') const isDocker = require('is-docker') -const APP_PORT = 3000 +const APP_PORT = process.env.PORT || 3000 // the docker compose service is called redis let host = 'localhost' diff --git a/servers/fastify/session/https-session-server/https-session-server.js b/servers/fastify/session/https-session-server/https-session-server.js index 1c56b6c7..127ed932 100644 --- a/servers/fastify/session/https-session-server/https-session-server.js +++ b/servers/fastify/session/https-session-server/https-session-server.js @@ -6,7 +6,7 @@ const fastifySession = require('fastify-session') const fastifyCookie = require('fastify-cookie') const fs = require('fs') -const APP_PORT = 3000 +const APP_PORT = process.env.PORT || 3000 const getCertificates = () => { const cert = fs.readFileSync(path.join(__dirname, './certificates/selfsigned.crt'), 'utf-8') const key = fs.readFileSync(path.join(__dirname, './certificates/selfsigned.key'), 'utf-8') From bdf411589da16858839592dd489fe5282a8695be Mon Sep 17 00:00:00 2001 From: Glenn Hinks Date: Thu, 27 Aug 2020 12:08:02 -0400 Subject: [PATCH 09/12] feature: fastify/session Roll back to using a client for redis. @mcollina suggested I use fastify-redis. I think in the case where I am using fastify-session, I need to provide a store, and that store needs a redis client. As the fastify-redis uses a decorator it is not available at the time I register fastify-session and so using the client directly is the only way to do this. Please correct, still getting to grips with the framework, but others are liking it too. --- .../https-session-server-redis.js | 12 ++++++++++-- .../session/https-session-server-redis/package.json | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/servers/fastify/session/https-session-server-redis/https-session-server-redis.js b/servers/fastify/session/https-session-server-redis/https-session-server-redis.js index d0aba9df..e2684bce 100644 --- a/servers/fastify/session/https-session-server-redis/https-session-server-redis.js +++ b/servers/fastify/session/https-session-server-redis/https-session-server-redis.js @@ -6,8 +6,11 @@ const fastifySession = require('fastify-session') const fastifyCookie = require('fastify-cookie') const fs = require('fs') const isDocker = require('is-docker') +const redis = require('redis') +const RedisStore = require('connect-redis')(fastifySession) const APP_PORT = process.env.PORT || 3000 +const REDIS_PORT = 6379 // the docker compose service is called redis let host = 'localhost' @@ -15,6 +18,11 @@ if (isDocker()) { host = 'redis' } +const redisClient = redis.createClient({ + host, + port: REDIS_PORT +}) + const getCertificates = () => { const cert = fs.readFileSync(path.join(__dirname, './certificates/selfsigned.crt'), 'utf-8') const key = fs.readFileSync(path.join(__dirname, './certificates/selfsigned.key'), 'utf-8') @@ -34,7 +42,6 @@ const fastify = Fastify({ }) fastify.register(fastifyCookie) -fastify.register(require('fastify-redis'), { host }) const sessionOptions = { secret: 'a secret with minimum length of 32 characters', @@ -42,7 +49,8 @@ const sessionOptions = { cookie: { secure: true, maxAge: 1000 * 60 * 3 - } + }, + store: new RedisStore({ client: redisClient }) } fastify.register(fastifySession, sessionOptions) diff --git a/servers/fastify/session/https-session-server-redis/package.json b/servers/fastify/session/https-session-server-redis/package.json index d6583684..bbbdcf03 100644 --- a/servers/fastify/session/https-session-server-redis/package.json +++ b/servers/fastify/session/https-session-server-redis/package.json @@ -13,8 +13,8 @@ "connect-redis": "^5.0.0", "fastify": "^3.2.0", "fastify-cookie": "^4.0.2", - "fastify-redis": "^4.0.3", "fastify-session": "^5.0.0", - "is-docker": "^2.1.1" + "is-docker": "^2.1.1", + "redis": "^3.0.2" } } From 84442b54e6020c6f93edf49638f6940f97928da4 Mon Sep 17 00:00:00 2001 From: Glenn Hinks Date: Fri, 28 Aug 2020 07:57:57 -0400 Subject: [PATCH 10/12] feature: fastify/multiple sessions attempt multiple sessions to see what is happening. --- servers/fastify/session/README.md | 2 + .../https-session-server-redis.js | 58 ++++++++++--------- .../https-session-server-redis/package.json | 4 +- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/servers/fastify/session/README.md b/servers/fastify/session/README.md index db520f9b..701cf817 100644 --- a/servers/fastify/session/README.md +++ b/servers/fastify/session/README.md @@ -61,3 +61,5 @@ Each time you hit the url the response will tell you how many times you requeste "hello": "route requested 6 times in this session" } ``` +Note the use of **await** when registering **fastify-redis** as we want the redis client available when we give the +fastify session its options. diff --git a/servers/fastify/session/https-session-server-redis/https-session-server-redis.js b/servers/fastify/session/https-session-server-redis/https-session-server-redis.js index e2684bce..1ce1e165 100644 --- a/servers/fastify/session/https-session-server-redis/https-session-server-redis.js +++ b/servers/fastify/session/https-session-server-redis/https-session-server-redis.js @@ -6,11 +6,9 @@ const fastifySession = require('fastify-session') const fastifyCookie = require('fastify-cookie') const fs = require('fs') const isDocker = require('is-docker') -const redis = require('redis') -const RedisStore = require('connect-redis')(fastifySession) +const RedisStore = require('connect-redis')(fastifySession); -const APP_PORT = process.env.PORT || 3000 -const REDIS_PORT = 6379 +const APP_PORT = 3000 // the docker compose service is called redis let host = 'localhost' @@ -18,11 +16,6 @@ if (isDocker()) { host = 'redis' } -const redisClient = redis.createClient({ - host, - port: REDIS_PORT -}) - const getCertificates = () => { const cert = fs.readFileSync(path.join(__dirname, './certificates/selfsigned.crt'), 'utf-8') const key = fs.readFileSync(path.join(__dirname, './certificates/selfsigned.key'), 'utf-8') @@ -41,29 +34,38 @@ const fastify = Fastify({ logger: true }) -fastify.register(fastifyCookie) +const initialization = async () => { + fastify.register(fastifyCookie) + await fastify.register(require('fastify-redis'), { host }) + const { redis } = fastify; + const sessionOptions = { + secret: 'a secret with minimum length of 32 characters', + cookieName: 'example-redis-session', + cookie: { + secure: true, + maxAge: 1000 * 60 * 3 + }, + store: new RedisStore({ client: redis }) + } + fastify.register(fastifySession, sessionOptions) -const sessionOptions = { - secret: 'a secret with minimum length of 32 characters', - cookieName: 'example-redis-session', - cookie: { - secure: true, - maxAge: 1000 * 60 * 3 - }, - store: new RedisStore({ client: redisClient }) -} -fastify.register(fastifySession, sessionOptions) + fastify.get('/', (request, reply) => { + if (request.session) { + request.session.count = request.session.count ? request.session.count + 1 : 1 + } + return { hello: `route requested ${request.session.count} times in this session` } + }) -fastify.get('/', async (request, reply) => { - if (request.session) { - request.session.count = request.session.count ? request.session.count + 1 : 1 - } - return { hello: `route requested ${request.session.count} times in this session` } -}) + fastify.listen(APP_PORT, '0.0.0.0', (err) => { + if (err) { + fastify.log.error(err) + process.exit(1) + } + }) +} -fastify.listen(APP_PORT, '0.0.0.0', (err) => { +initialization().catch((err) => { if (err) { fastify.log.error(err) - process.exit(1) } }) diff --git a/servers/fastify/session/https-session-server-redis/package.json b/servers/fastify/session/https-session-server-redis/package.json index bbbdcf03..d6583684 100644 --- a/servers/fastify/session/https-session-server-redis/package.json +++ b/servers/fastify/session/https-session-server-redis/package.json @@ -13,8 +13,8 @@ "connect-redis": "^5.0.0", "fastify": "^3.2.0", "fastify-cookie": "^4.0.2", + "fastify-redis": "^4.0.3", "fastify-session": "^5.0.0", - "is-docker": "^2.1.1", - "redis": "^3.0.2" + "is-docker": "^2.1.1" } } From f0bffd6f2e267d81cd3fe9403b344fb810898fe9 Mon Sep 17 00:00:00 2001 From: Glenn Hinks Date: Fri, 28 Aug 2020 08:03:32 -0400 Subject: [PATCH 11/12] docs: fastify/session markdown lint correction --- servers/fastify/session/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/servers/fastify/session/README.md b/servers/fastify/session/README.md index 701cf817..3237b827 100644 --- a/servers/fastify/session/README.md +++ b/servers/fastify/session/README.md @@ -61,5 +61,6 @@ Each time you hit the url the response will tell you how many times you requeste "hello": "route requested 6 times in this session" } ``` -Note the use of **await** when registering **fastify-redis** as we want the redis client available when we give the + +Note the use of **await** when registering **fastify-redis** as we want the redis client available when we give the fastify session its options. From 40011afc87731400691ec262cd118b4d52c5f0fd Mon Sep 17 00:00:00 2001 From: Glenn Hinks Date: Sun, 27 Sep 2020 07:48:25 -0400 Subject: [PATCH 12/12] docs: fastify/session markdown correct openssl command missing 'o' --- servers/fastify/session/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/servers/fastify/session/README.md b/servers/fastify/session/README.md index 3237b827..e8a5759b 100644 --- a/servers/fastify/session/README.md +++ b/servers/fastify/session/README.md @@ -32,7 +32,7 @@ start **fastify** as an https server it is necessary to provide certificates. Lo to save the user the difficulty of creating one. This is a command to create certificates. ```shell script -penssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout selfsigned.key -out selfsigned.crt -subj "/CN=localhost" +openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout selfsigned.key -out selfsigned.crt -subj "/CN=localhost" ``` The key and cert are created using [openssl](https://www.openssl.org/) and were created on a linux ubuntu system. The