Skip to content

Commit

Permalink
fix: examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Ringrose committed Sep 11, 2024
1 parent 9c22dc0 commit e991e46
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
5 changes: 3 additions & 2 deletions example/reactSSR/handlers/react.handler.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { JSX, ReactNode } from "react";
import { renderToString } from "react-dom/server";
import { Handler, RequestContext, ssr } from "../../../mod.ts";
import htmlTemplate from "../src/document.ts";

export const reactHandler =
(
component: (props: Record<string, unknown>) => unknown,
component: (props: Record<string, ReactNode>) => JSX.Element,
title: string,
entrypoint: string
): Handler =>
(ctx: RequestContext<{ env?: { ENVIRONMENT: string } }>) => {
return ssr(
() => {
const ssrHTML = renderToString(component(ctx.state), null);
const ssrHTML = renderToString(component(ctx.state as Record<string, ReactNode>));
return htmlTemplate({
title,
ssrHTML,
Expand Down
2 changes: 1 addition & 1 deletion example/singleFileAuth/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Peko from "../../mod.ts"; // "https://deno.land/x/peko/mod.ts"

const html = String;
const router = new Peko.Router();
const router = new Peko.HttpRouter();
const crypto = new Peko.Crypto("SUPER_SECRET_KEY_123"); // <-- replace from env
const user = {
// <-- replace with db / auth provider query
Expand Down
1 change: 1 addition & 0 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// Routers & types
export * from "./lib/routers/httpRouter.ts";
export * from "./lib/context.ts";
export * from "./lib/types.ts";

// Handlers
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"scripts": {
"build": "esbuild --bundle --sourcemap --target=es2020 --platform=browser --format=esm --outdir=./example/reactSSR/dist/pages --external:react --jsx=automatic --tsconfig-raw={} ./example/reactSSR/src/pages/*.tsx",
"start": "deno run --allow-net --allow-read --allow-env --allow-run scripts/deno/main.ts",
"start:auth": "deno run --allow-net --allow-read --allow-env --allow-run scripts/deno/auth.ts",
"test": "deno test --allow-read --allow-net",
"profile:deno": "deno run --allow-read --allow-net scripts/deno/profile.ts",
"profile:bun": "bun run scripts/bun/profile.ts",
Expand Down
15 changes: 15 additions & 0 deletions scripts/deno/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import router from "../../example/singleFileAuth/app.ts";

router.middleware.unshift((ctx) => {
ctx.state.env = Deno.env.toObject();
});

// Start Deno server with Peko router :^)
Deno.serve(
{
port: 7777,
},
(req) => router.handle(req)
);

console.log("Deno server running with Peko router <3");

0 comments on commit e991e46

Please sign in to comment.