Merge branch 'dev'
This commit is contained in:
commit
fca1077310
7 changed files with 9 additions and 167 deletions
|
@ -1,18 +0,0 @@
|
||||||
/**
|
|
||||||
* By default, Remix will handle hydrating your app on the client for you.
|
|
||||||
* You are free to delete this file if you'd like to, but if you ever want it revealed again, you can run `npx remix reveal` ✨
|
|
||||||
* For more information, see https://remix.run/file-conventions/entry.client
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { RemixBrowser } from "@remix-run/react";
|
|
||||||
import { startTransition, StrictMode } from "react";
|
|
||||||
import { hydrateRoot } from "react-dom/client";
|
|
||||||
|
|
||||||
startTransition(() => {
|
|
||||||
hydrateRoot(
|
|
||||||
document,
|
|
||||||
<StrictMode>
|
|
||||||
<RemixBrowser />
|
|
||||||
</StrictMode>
|
|
||||||
);
|
|
||||||
});
|
|
|
@ -1,137 +0,0 @@
|
||||||
/**
|
|
||||||
* By default, Remix will handle generating the HTTP Response for you.
|
|
||||||
* You are free to delete this file if you'd like to, but if you ever want it revealed again, you can run `npx remix reveal` ✨
|
|
||||||
* For more information, see https://remix.run/file-conventions/entry.server
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { PassThrough } from "node:stream";
|
|
||||||
|
|
||||||
import type { AppLoadContext, EntryContext } from "@remix-run/node";
|
|
||||||
import { createReadableStreamFromReadable } from "@remix-run/node";
|
|
||||||
import { RemixServer } from "@remix-run/react";
|
|
||||||
import isbot from "isbot";
|
|
||||||
import { renderToPipeableStream } from "react-dom/server";
|
|
||||||
|
|
||||||
const ABORT_DELAY = 5_000;
|
|
||||||
|
|
||||||
export default function handleRequest(
|
|
||||||
request: Request,
|
|
||||||
responseStatusCode: number,
|
|
||||||
responseHeaders: Headers,
|
|
||||||
remixContext: EntryContext,
|
|
||||||
loadContext: AppLoadContext
|
|
||||||
) {
|
|
||||||
return isbot(request.headers.get("user-agent"))
|
|
||||||
? handleBotRequest(
|
|
||||||
request,
|
|
||||||
responseStatusCode,
|
|
||||||
responseHeaders,
|
|
||||||
remixContext
|
|
||||||
)
|
|
||||||
: handleBrowserRequest(
|
|
||||||
request,
|
|
||||||
responseStatusCode,
|
|
||||||
responseHeaders,
|
|
||||||
remixContext
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleBotRequest(
|
|
||||||
request: Request,
|
|
||||||
responseStatusCode: number,
|
|
||||||
responseHeaders: Headers,
|
|
||||||
remixContext: EntryContext
|
|
||||||
) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
let shellRendered = false;
|
|
||||||
const { pipe, abort } = renderToPipeableStream(
|
|
||||||
<RemixServer
|
|
||||||
context={remixContext}
|
|
||||||
url={request.url}
|
|
||||||
abortDelay={ABORT_DELAY}
|
|
||||||
/>,
|
|
||||||
{
|
|
||||||
onAllReady() {
|
|
||||||
shellRendered = true;
|
|
||||||
const body = new PassThrough();
|
|
||||||
const stream = createReadableStreamFromReadable(body);
|
|
||||||
|
|
||||||
responseHeaders.set("Content-Type", "text/html");
|
|
||||||
|
|
||||||
resolve(
|
|
||||||
new Response(stream, {
|
|
||||||
headers: responseHeaders,
|
|
||||||
status: responseStatusCode,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
pipe(body);
|
|
||||||
},
|
|
||||||
onShellError(error: unknown) {
|
|
||||||
reject(error);
|
|
||||||
},
|
|
||||||
onError(error: unknown) {
|
|
||||||
responseStatusCode = 500;
|
|
||||||
// Log streaming rendering errors from inside the shell. Don't log
|
|
||||||
// errors encountered during initial shell rendering since they'll
|
|
||||||
// reject and get logged in handleDocumentRequest.
|
|
||||||
if (shellRendered) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
setTimeout(abort, ABORT_DELAY);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleBrowserRequest(
|
|
||||||
request: Request,
|
|
||||||
responseStatusCode: number,
|
|
||||||
responseHeaders: Headers,
|
|
||||||
remixContext: EntryContext
|
|
||||||
) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
let shellRendered = false;
|
|
||||||
const { pipe, abort } = renderToPipeableStream(
|
|
||||||
<RemixServer
|
|
||||||
context={remixContext}
|
|
||||||
url={request.url}
|
|
||||||
abortDelay={ABORT_DELAY}
|
|
||||||
/>,
|
|
||||||
{
|
|
||||||
onShellReady() {
|
|
||||||
shellRendered = true;
|
|
||||||
const body = new PassThrough();
|
|
||||||
const stream = createReadableStreamFromReadable(body);
|
|
||||||
|
|
||||||
responseHeaders.set("Content-Type", "text/html");
|
|
||||||
|
|
||||||
resolve(
|
|
||||||
new Response(stream, {
|
|
||||||
headers: responseHeaders,
|
|
||||||
status: responseStatusCode,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
pipe(body);
|
|
||||||
},
|
|
||||||
onShellError(error: unknown) {
|
|
||||||
reject(error);
|
|
||||||
},
|
|
||||||
onError(error: unknown) {
|
|
||||||
responseStatusCode = 500;
|
|
||||||
// Log streaming rendering errors from inside the shell. Don't log
|
|
||||||
// errors encountered during initial shell rendering since they'll
|
|
||||||
// reject and get logged in handleDocumentRequest.
|
|
||||||
if (shellRendered) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
setTimeout(abort, ABORT_DELAY);
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -6,7 +6,7 @@ import { useState } from "react";
|
||||||
import LoadingIndicator from "~/components/LoadingIndicator";
|
import LoadingIndicator from "~/components/LoadingIndicator";
|
||||||
import { useEventSource } from "remix-utils/sse/react";
|
import { useEventSource } from "remix-utils/sse/react";
|
||||||
import { useUser } from "@clerk/remix";
|
import { useUser } from "@clerk/remix";
|
||||||
import { isAdmin, isVIP } from "~/services/helpers";
|
import { isAdmin, isVIP } from "~/services/helpers.client";
|
||||||
|
|
||||||
export const loader: LoaderFunction = async (args) => {
|
export const loader: LoaderFunction = async (args) => {
|
||||||
const { userId } = await getAuth(args);
|
const { userId } = await getAuth(args);
|
||||||
|
|
|
@ -17,13 +17,17 @@ import {
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import LoadingIndicator from "~/components/LoadingIndicator";
|
import LoadingIndicator from "~/components/LoadingIndicator";
|
||||||
import { useEventSource } from "remix-utils/sse/react";
|
import { useEventSource } from "remix-utils/sse/react";
|
||||||
import { PresenceItem, RoomResponse, VoteResponse } from "~/services/types";
|
import {
|
||||||
import { isAdmin, jsonToCsv } from "~/services/helpers";
|
PresenceItem,
|
||||||
|
RoomResponse,
|
||||||
|
VoteResponse,
|
||||||
|
} from "~/services/types.client";
|
||||||
|
import { isAdmin, jsonToCsv } from "~/services/helpers.client";
|
||||||
import { useUser } from "@clerk/remix";
|
import { useUser } from "@clerk/remix";
|
||||||
import { db } from "~/services/db.server";
|
import { db } from "~/services/db.server";
|
||||||
import { rooms } from "~/services/schema";
|
import { rooms } from "~/services/schema";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import { shitList } from "~/services/consts";
|
import { shitList } from "~/services/consts.server";
|
||||||
|
|
||||||
// Loader
|
// Loader
|
||||||
export const loader: LoaderFunction = async (args) => {
|
export const loader: LoaderFunction = async (args) => {
|
||||||
|
|
|
@ -1,11 +1,4 @@
|
||||||
type BetterEnum<T> = T[keyof T];
|
// type BetterEnum<T> = T[keyof T];
|
||||||
|
|
||||||
export const EventTypes = {
|
|
||||||
ROOM_LIST_UPDATE: "room.list.update",
|
|
||||||
ROOM_UPDATE: "room.update",
|
|
||||||
VOTE_UPDATE: "vote.update",
|
|
||||||
} as const;
|
|
||||||
export type EventType = BetterEnum<typeof EventTypes>;
|
|
||||||
|
|
||||||
export interface PresenceItem {
|
export interface PresenceItem {
|
||||||
id: string;
|
id: string;
|
Loading…
Add table
Reference in a new issue