Skip to content
This repository has been archived by the owner on Jun 22, 2024. It is now read-only.

Feature/fastify examples session #26

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

ghinks
Copy link

@ghinks ghinks commented Aug 19, 2020

A slightly more advanced example starting with

  • localhost http local memory store
  • localhost https local memory store
  • localhost https redis memory store with docker-compose

Session storage three examples all localhost
- simple http
- simple https
- redis based storage over https
update the docs with docker instructions.
markdown lint corrections
A markdownlintignore file has been added as there will be multiple folders which contain node module readmes that do not comply.
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to prefer to recommend the use of of https://github.com/fastify/fastify-cookie (with the signature) or https://github.com/fastify/fastify-secure-session.

take feedback and update as suggested.
alter the host name to take account of whether it is inside a docker container or not
@ghinks ghinks requested a review from mcollina August 20, 2020 20:28
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why all the routes stopped being async?

@ghinks
Copy link
Author

ghinks commented Aug 22, 2020

@mcollina ok, so there may be a misunderstanding by myself on this subject. Should all route handlers be async even if they are synchronous themselves. Is this a general practice? Or am I doing this correctly but you would rather see examples of asynchronous behavior with these session examples too? ( PS sincere thanks for reviewing )

@mcollina
Copy link
Member

Should all route handlers be async even if they are synchronous themselves. Is this a general practice?

I recommend this for examples because adding an asynchronous behavior is the normal case. There are significant differences between returning a value (or throwing) in an async function vs a normal one as everything is wrapped in a promise, it resolves in the next tick etc.

Starting from v3 this pattern is supported so everything works fine here, but it looks good only in non-production cases.

@ghinks
Copy link
Author

ghinks commented Aug 24, 2020

ok, understood. I thought that was what you would say. Will make appropriate changes.

add logging to examples where it was missing
use async in all route handlers
use consistent listen handler across examples
@@ -6,6 +6,7 @@ const Fastify = require('fastify')
const fastifySession = require('fastify-session')
const fastifyCookie = require('fastify-cookie')

const APP_PORT = 3000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const APP_PORT = 3000
const APP_PORT = process.env.PORT || 3000

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

use PORT from the environment first to decide where to listen.
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

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.
@ghinks
Copy link
Author

ghinks commented Aug 28, 2020

Then I shall try that. Live and Learn :)

attempt multiple sessions to see what is happening.
markdown lint correction
@@ -41,29 +34,38 @@ const fastify = Fastify({
logger: true
})

fastify.register(fastifyCookie)
const initialization = async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you pass in the fastify app as a parameter, you can export this function and make this easily testable. I would also move the listen outside.

Suggested change
const initialization = async () => {
const initialization = async (app) => {

Copy link
Contributor

@bnb bnb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So a couple notes (again!):

The REAME shouldn't be in the vein of a tutorial - it should be more like a README if you were to publish this project as a standalone project on GitHub. Here are a few generic examples of the style I'm talking about. Definitely feel free to publish it as an article, though 👍🏻

Will test the docker-compose bits soon, but wanted to give this feedback ASAP.

@bnb
Copy link
Contributor

bnb commented Sep 25, 2020

cc @mhdawson is including an SSL cert here okay given the cryptography exports thing?

@bnb bnb closed this Sep 25, 2020
@bnb bnb reopened this Sep 25, 2020
@bnb
Copy link
Contributor

bnb commented Sep 25, 2020

oops didn't mean to close

@ghinks
Copy link
Author

ghinks commented Sep 27, 2020

many thanks for the comments. I shall update the readme to follow the style suggested. The certificates are local host and are self signed. There are no cryptographic secrets within them they just allow for session to be tested on localhost using the secure setting. Otherwise the example is not representative.

markdown correct openssl command missing 'o'
@ghinks
Copy link
Author

ghinks commented Sep 27, 2020

I have had a look at the example readme files you gave. Apart from the IBM example they are all installable modules and only the IBM readme is an example, so they don't really pertain to this type of examples repo. The IBM readme does in fact start off with in this tutorial. I am not really sure what is being asked for.

@bnb
Copy link
Contributor

bnb commented Dec 10, 2020

Here's an example of a server from @Thiruppathi that aligns more with what's being asked for :)

6f689d5

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants