Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
ynwd committed Nov 28, 2024
1 parent 9d17443 commit 38396e8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
6 changes: 3 additions & 3 deletions core/render/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
h,
JSX,
renderToString,
renderToStringAsync,
// renderToStringAsync,
VNode,
} from "../server/deps.ts";
import { Fastro, FunctionComponent, Page } from "../server/types.ts";
Expand Down Expand Up @@ -118,7 +118,7 @@ es.onmessage = function(e) {
return layout;
};

render = async <T = any>(
render = <T = any>(
key: string,
p: Page,
data: T,
Expand All @@ -143,7 +143,7 @@ es.onmessage = function(e) {
nonce,
);
}
const html = "<!DOCTYPE html>" + await renderToStringAsync(app);
const html = "<!DOCTYPE html>" + renderToString(app);
const headers = hdr ? hdr : new Headers({
"content-type": "text/html",
"x-request-id": new Date().getTime().toString(),
Expand Down
7 changes: 4 additions & 3 deletions core/server/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -398,11 +399,11 @@ if (root) fetchProps(root);
ctx.kv = this.serverOptions["kv"];
ctx.options = this.serverOptions;
ctx.stores = this.stores;
ctx.render = async <T>(data: T, headers?: Headers) => {
ctx.render = <T>(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 = <T>(data: T, status = 200, headers?: Headers) => {
return createResponse(data, status, headers);
Expand Down
36 changes: 18 additions & 18 deletions modules/index/index.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
1 change: 1 addition & 0 deletions modules/socket/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 38396e8

Please sign in to comment.