A Pen by Johan Fagerbeg on CodePen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ReactDOMServer from "react-dom/server"; | |
| import type { EntryContext } from "@remix-run/core"; | |
| import Remix from "@remix-run/react/server"; | |
| import { renderToString } from "react-dom/server"; | |
| import { ServerStyleSheet } from "styled-components"; | |
| import StylesContext from "./stylesContext"; | |
| export default function handleRequest( | |
| request: Request, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| enum State { | |
| Idle, | |
| LoadingJwt, | |
| Success, | |
| Error, | |
| } | |
| type Data = { error?: string; jwt?: string }; | |
| function Comp() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| const express = require("express"); | |
| const compression = require("compression"); | |
| const morgan = require("morgan"); | |
| const { createRequestHandler } = require("@remix-run/express"); | |
| //////////////////////////////////////////////////////////////////////////////// | |
| let app = express(); | |
| app.use(compression()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import type { | |
| ActionFunction, | |
| LinksFunction, | |
| LoaderFunction, | |
| MetaFunction | |
| } from "@remix-run/react"; | |
| import { | |
| Meta, | |
| Links, | |
| Scripts, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import crypto from "crypto"; | |
| import { renderToStaticMarkup } from "react-dom/server"; | |
| import createMailgun from "mailgun-js"; | |
| import type { ActionFunction, LoaderFunction, Session } from "remix"; | |
| import { createCookieSessionStorage, json, redirect } from "remix"; | |
| /******************************************************************************* | |
| * Before we can do anything, we need to make sure the environment has | |
| * everything we need. If anything is missing, we just prevent the app from | |
| * starting up. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createCookieSessionStorage } from "remix"; | |
| let { getSession, commitSession, destroySession } = createCookieSessionStorage({ | |
| cookie: { | |
| name: "__session", | |
| secrets: ["r3m1xr0ck5"] | |
| } | |
| }); | |
| export { getSession, commitSession, destroySession }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // root.tsx | |
| import { getUserSession, requireUser, logout } from "~/session"; | |
| export function loader({ request }) { | |
| // use case: know if the user is logged in, no redirect to /login | |
| let userSession = await getUserSession(request); | |
| let isAuthenticated = userSession.has("userId"); | |
| return { isAuthenticated }; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Get a random floating point number between `min` and `max`. | |
| * | |
| * @param {number} min - min number | |
| * @param {number} max - max number | |
| * @return {number} a random floating point number | |
| */ | |
| function getRandomFloat(min, max) { | |
| return Math.random() * (max - min) + min; | |
| } |