diff --git a/core/render/render.ts b/core/render/render.ts index dd18258f..9ac9155e 100644 --- a/core/render/render.ts +++ b/core/render/render.ts @@ -4,7 +4,7 @@ import { h, JSX, renderToString, - renderToStringAsync, + // renderToStringAsync, VNode, } from "../server/deps.ts"; import { Fastro, FunctionComponent, Page } from "../server/types.ts"; @@ -118,7 +118,7 @@ es.onmessage = function(e) { return layout; }; - render = async ( + render = ( key: string, p: Page, data: T, @@ -143,7 +143,7 @@ es.onmessage = function(e) { nonce, ); } - const html = "" + await renderToStringAsync(app); + const html = "" + renderToString(app); const headers = hdr ? hdr : new Headers({ "content-type": "text/html", "x-request-id": new Date().getTime().toString(), diff --git a/core/server/mod.ts b/core/server/mod.ts index 08fc30e7..24b773d2 100644 --- a/core/server/mod.ts +++ b/core/server/mod.ts @@ -23,6 +23,7 @@ import { import { EsbuildMod } from "../build/esbuildMod.ts"; import { Store } from "../map/mod.ts"; import { createTaskQueue } from "@app/utils/queue.ts"; +import { ulid } from "jsr:@std/ulid/ulid"; export function checkReferer(req: Request) { const referer = req.headers.get("referer"); @@ -86,7 +87,7 @@ export default class Server implements Fastro { } getNonce(): string { if (this.#nonce === "") { - this.#nonce = crypto.randomUUID().replace(/-/g, ""); + this.#nonce = ulid(); } return this.#nonce; } @@ -398,11 +399,11 @@ if (root) fetchProps(root); ctx.kv = this.serverOptions["kv"]; ctx.options = this.serverOptions; ctx.stores = this.stores; - ctx.render = async (data: T, headers?: Headers) => { + ctx.render = (data: T, headers?: Headers) => { const r = new Render(this); key = key === "/" ? "" : key; key = url.origin + "/__/props" + key; - return await r.render(key, page, data, this.getNonce(), headers); + return r.render(key, page, data, this.getNonce(), headers); }; ctx.send = (data: T, status = 200, headers?: Headers) => { return createResponse(data, status, headers); diff --git a/modules/index/index.handler.ts b/modules/index/index.handler.ts index d50a86ab..a62de07f 100644 --- a/modules/index/index.handler.ts +++ b/modules/index/index.handler.ts @@ -32,29 +32,29 @@ export const handler = async (req: HttpRequest, ctx: Context) => { ? "wss://fastro.dev" : "ws://localhost:8000"; - if (ses) { - return ctx.render({ + const obj = ses + ? { title: "Under construction ~ Home", isLogin: true, avatar_url: ses?.avatar_url, html_url: ses?.html_url, ws_url, username: ses?.username, - }); - } + } + : { + title: "Fast & Modular Web Framework", + description: + "Enhance SSR web app maintainability through a flat modular architecture", + image: "https://fastro.dev/fastro.png", + start: Deno.env.get("ENV") === "DEVELOPMENT" + ? "http://localhost:8000/docs/start" + : "https://fastro.dev/docs/start", + baseUrl: Deno.env.get("ENV") === "DEVELOPMENT" + ? "http://localhost:8000" + : "https://fastro.dev", + new: "Using Queues to Avoid Race Conditions", + destination: "blog/queue", + }; - return ctx.render({ - title: "Fast & Modular Web Framework", - description: - "Enhance SSR web app maintainability through a flat modular architecture", - image: "https://fastro.dev/fastro.png", - start: Deno.env.get("ENV") === "DEVELOPMENT" - ? "http://localhost:8000/docs/start" - : "https://fastro.dev/docs/start", - baseUrl: Deno.env.get("ENV") === "DEVELOPMENT" - ? "http://localhost:8000" - : "https://fastro.dev", - new: "Using Queues to Avoid Race Conditions", - destination: "blog/queue", - }); + return await ctx.render(obj); }; diff --git a/modules/socket/mod.ts b/modules/socket/mod.ts index 299dac03..b0b3be25 100644 --- a/modules/socket/mod.ts +++ b/modules/socket/mod.ts @@ -37,6 +37,7 @@ export default function socketModule(s: Fastro) { const c = ctx.stores.get("connected"); if (!c) return; const entries = c.entries().toArray(); + console.log("entries", JSON.stringify(entries)); const connected = Array.from(entries).map(([, { value }]) => ({ username: value.data.username, room: value.data.room,