Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarification needed on hattip-entry file #111

Open
rondonjon opened this issue Apr 5, 2023 · 4 comments
Open

Clarification needed on hattip-entry file #111

rondonjon opened this issue Apr 5, 2023 · 4 comments
Labels
📖 documentation Improvements or additions to documentation

Comments

@rondonjon
Copy link

I am trying to add cookie / session support to my rakkasjs project.

The docs give some instructions on how this might be achieved, but I am still unsure if I am doing it right.

I think it would be helpful to clarify the following points in the documentation:

  • are the listed "available" hattip modules already loaded by rakkasjs, or is this merely an information on what we might want to add to a custom configuration?
  • the page mentions a default implementation, but now where to find and how to build upon it.
  • Will a custom configuration (if present) replace the default or extend it? If replacing: should we manually extend the defaults to ensure that we're not losing functionality?

I am new to both rakkasjs and hattip and find this part very confusing.

@cyco130
Copy link
Member

cyco130 commented Apr 5, 2023

Hi,

Thank you for your interest!

See the session example in the repo, it should give you the direction in which to start.

The entry-hattip file is for customizing the server. If you don't provide one, nothing is customized and Rakkas acts as if you provided the following:

import { createRequestHandler } from "rakkasjs";
export default createRequestHandler();

The docs show all the options you can pass to createRequestHandler, all which are optional. For session support, you'd add cookie and session middlewares using the middleware.beforePages option:

import { createRequestHandler } from "rakkasjs";
import { cookie } from "@hattip/cookie";
import { session, SimpleCookieStore } from "@hattip/session";

// Declare session data type
declare module "@hattip/session" {
  interface SessionData {
    foo: string;
    bar: number;
  }
}

export default createRequestHandler({
  middleware: {
    beforePages: [
      cookie(),
      session({
        store: new SimpleCookieStore(),
        defaultSessionData: { foo: "xyz", bar: 42 },
        cookieOptions: {
          httpOnly: true,
          secure: import.meta.env.PROD,
          path: "/",
          maxAge: 60 * 60 * 1000, // 1 week
        },
      }),
    ],
  },
});

I know how frustrating it can be when the documentation isn't great, feel free to ping me on Rakkas Discord channel or my Twitter DMs for quick questions on getting started.

@rondonjon
Copy link
Author

Hello @cyco130, thanks so much for taking the time to reply and to reply so extensively. I have replaced my implementation with an adjusted version of your example, and the application is now working 😊

@rondonjon rondonjon reopened this Apr 6, 2023
@rondonjon
Copy link
Author

Reopened because I think this part from your answer might help others, too, if it was taken into the documentation:

The entry-hattip file is for customizing the server. If you don't provide one, nothing is customized and Rakkas
acts as if you provided the following:

import { createRequestHandler } from "rakkasjs";
export default createRequestHandler();

@cyco130
Copy link
Member

cyco130 commented Apr 6, 2023

Yes, let's leave it open. It'll serve as a reminder for me to update the docs :)

@cyco130 cyco130 added the 📖 documentation Improvements or additions to documentation label May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📖 documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants