Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor runtime packages to conform to the Remix server runtime interface #2359

Merged
merged 17 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
26dcec2
feat(@remix-run/server-runtime): define interface for remix server ru…
pcattori Mar 17, 2022
c89c559
refactor(@remix-run/server-runtime): organize exports
pcattori Mar 17, 2022
0943d5b
refactor(@remix-run/server-runtime): factories for crypto-dependent i…
pcattori Mar 19, 2022
23ad936
docs(@remix-run/server-runtime): rewrite readme to explain the "remix…
pcattori Mar 18, 2022
47d60b1
refactor(@remix-run/node): conform to the remix server runtime interface
pcattori Mar 17, 2022
06ec5bb
refactor(@remix-run/node): implement crypto-dependent interface funct…
pcattori Mar 19, 2022
88b6520
feat(@remix-run/cloudflare): create new server runtime package for cl…
pcattori Mar 18, 2022
58b8d0e
refactor(@remix-run/cloudflare): implement crypto-dependent interface…
pcattori Mar 19, 2022
ff288df
refactor(remix-deno): conform to the remix server runtime interface
pcattori Mar 18, 2022
d177502
refactor(remix-deno): implement crypto-dependent interface functions
pcattori Mar 19, 2022
fc32193
refactor(@remix-run/architect): use `@remix-run/node` instead of `@re…
pcattori Mar 18, 2022
a282e08
refactor(@remix-run/express): use `@remix-run/node` instead of `@remi…
pcattori Mar 18, 2022
a47504c
refactor(@remix-run/netlify): use `@remix-run/node` instead of `@remi…
pcattori Mar 18, 2022
467cfb9
refactor(@remix-run/vercel): use `@remix-run/node` instead of `@remix…
pcattori Mar 18, 2022
346c2e1
refactor(@remix-run/cloudflare-workers): use `@remix-run/cloudflare` …
pcattori Mar 18, 2022
3f976a2
refactor(@remix-run/cloudflare-pages): use `@remix-run/cloudflare` in…
pcattori Mar 18, 2022
bd2fadf
refactor(server-runtimes,adapters): remove unused `platform` arg from…
pcattori Mar 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"packages/create-remix",
"packages/remix",
"packages/remix-architect",
"packages/remix-cloudflare",
"packages/remix-cloudflare-pages",
"packages/remix-cloudflare-workers",
"packages/remix-dev",
Expand Down
10 changes: 8 additions & 2 deletions packages/remix-architect/__tests__/server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import fsp from "fs/promises";
import path from "path";
import lambdaTester from "lambda-tester";
import type { APIGatewayProxyEventV2 } from "aws-lambda";
import { createRequestHandler as createRemixRequestHandler } from "@remix-run/server-runtime";
import {
// This has been added as a global in node 15+
AbortController,
createRequestHandler as createRemixRequestHandler,
mjackson marked this conversation as resolved.
Show resolved Hide resolved
Response as NodeResponse,
} from "@remix-run/node";

Expand All @@ -18,7 +18,13 @@ import {

// We don't want to test that the remix server works here (that's what the
// puppetteer tests do), we just want to test the architect adapter
jest.mock("@remix-run/server-runtime");
jest.mock("@remix-run/node", () => {
let original = jest.requireActual("@remix-run/node");
return {
...original,
createRequestHandler: jest.fn()
};
});
let mockedCreateRequestHandler =
createRemixRequestHandler as jest.MockedFunction<
typeof createRemixRequestHandler
Expand Down
3 changes: 1 addition & 2 deletions packages/remix-architect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
},
"dependencies": {
"@architect/functions": "^5.0.2",
"@types/aws-lambda": "^8.10.82",
"@remix-run/node": "1.3.2",
"@remix-run/server-runtime": "1.3.2"
"@types/aws-lambda": "^8.10.82"
},
"devDependencies": {
"@types/architect__functions": "^3.13.6",
Expand Down
10 changes: 4 additions & 6 deletions packages/remix-architect/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AbortController,
Headers as NodeHeaders,
Request as NodeRequest,
createRequestHandler as createRemixRequestHandler,
} from "@remix-run/node";
import type {
APIGatewayProxyEventHeaders,
Expand All @@ -13,10 +14,8 @@ import type {
import type {
AppLoadContext,
ServerBuild,
ServerPlatform,
} from "@remix-run/server-runtime";
import { createRequestHandler as createRemixRequestHandler } from "@remix-run/server-runtime";
import type { Response as NodeResponse } from "@remix-run/node";
Response as NodeResponse,
} from "@remix-run/node";

import { isBinaryType } from "./binary-types";

Expand Down Expand Up @@ -46,8 +45,7 @@ export function createRequestHandler({
getLoadContext?: GetLoadContextFunction;
mode?: string;
}): APIGatewayProxyHandlerV2 {
let platform: ServerPlatform = {};
let handleRequest = createRemixRequestHandler(build, platform, mode);
let handleRequest = createRemixRequestHandler(build, mode);

return async (event, _context) => {
let abortController = new AbortController();
Expand Down
7 changes: 2 additions & 5 deletions packages/remix-architect/sessions/arcTableSessionStorage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import * as crypto from "crypto";
import type {
SessionStorage,
SessionIdStorageStrategy,
} from "@remix-run/server-runtime";
import { createSessionStorage } from "@remix-run/server-runtime";
import type { SessionStorage, SessionIdStorageStrategy } from "@remix-run/node";
import { createSessionStorage } from "@remix-run/node";
import arc from "@architect/functions";
import type { ArcTable } from "@architect/functions/tables";

Expand Down
13 changes: 0 additions & 13 deletions packages/remix-cloudflare-pages/globals.ts

This file was deleted.

6 changes: 0 additions & 6 deletions packages/remix-cloudflare-pages/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
import { installGlobals } from "./globals";

export { createCloudflareKVSessionStorage } from "./sessions/cloudflareKVSessionStorage";
mjackson marked this conversation as resolved.
Show resolved Hide resolved

export type { createPagesFunctionHandlerParams } from "./worker";
export { createPagesFunctionHandler, createRequestHandler } from "./worker";

installGlobals();
2 changes: 1 addition & 1 deletion packages/remix-cloudflare-pages/magicExports/remix.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Re-export everything from this package that is available in `remix`.

export { createCloudflareKVSessionStorage } from "@remix-run/cloudflare-pages";
export { createCloudflareKVSessionStorage } from "@remix-run/cloudflare";
2 changes: 1 addition & 1 deletion packages/remix-cloudflare-pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"url": "https://github.com/remix-run/remix/issues"
},
"dependencies": {
"@remix-run/server-runtime": "1.3.2"
"@remix-run/cloudflare": "1.3.2"
},
"peerDependencies": {
"@cloudflare/workers-types": "^3.2.0"
Expand Down
1 change: 0 additions & 1 deletion packages/remix-cloudflare-pages/responses.ts

This file was deleted.

This file was deleted.

3 changes: 1 addition & 2 deletions packages/remix-cloudflare-pages/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export function createRequestHandler<Env = any>({
getLoadContext,
mode,
}: createPagesFunctionHandlerParams<Env>): PagesFunction<Env> {
let platform = {};
let handleRequest = createRemixRequestHandler(build, platform, mode);
let handleRequest = createRemixRequestHandler(build, mode);

return (context) => {
let loadContext =
Expand Down
52 changes: 0 additions & 52 deletions packages/remix-cloudflare-workers/cookieSigning.ts

This file was deleted.

18 changes: 0 additions & 18 deletions packages/remix-cloudflare-workers/globals.ts

This file was deleted.

6 changes: 0 additions & 6 deletions packages/remix-cloudflare-workers/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { installGlobals } from "./globals";

export { createCloudflareKVSessionStorage } from "./sessions/cloudflareKVSessionStorage";
mjackson marked this conversation as resolved.
Show resolved Hide resolved

export type { GetLoadContextFunction, RequestHandler } from "./worker";
export {
createEventHandler,
createRequestHandler,
handleAsset,
} from "./worker";

installGlobals();
2 changes: 1 addition & 1 deletion packages/remix-cloudflare-workers/magicExports/remix.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Re-export everything from this package that is available in `remix`.

export { createCloudflareKVSessionStorage } from "@remix-run/cloudflare-workers";
export { createCloudflareKVSessionStorage } from "@remix-run/cloudflare";
2 changes: 1 addition & 1 deletion packages/remix-cloudflare-workers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"@cloudflare/kv-asset-handler": "^0.1.3",
"@remix-run/server-runtime": "1.3.2"
"@remix-run/cloudflare": "1.3.2"
},
"peerDependencies": {
"@cloudflare/workers-types": "^2.2.2"
Expand Down
1 change: 0 additions & 1 deletion packages/remix-cloudflare-workers/responses.ts

This file was deleted.

8 changes: 3 additions & 5 deletions packages/remix-cloudflare-workers/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import {
import type {
AppLoadContext,
ServerBuild,
ServerPlatform,
} from "@remix-run/server-runtime";
import { createRequestHandler as createRemixRequestHandler } from "@remix-run/server-runtime";
} from "@remix-run/cloudflare";
import { createRequestHandler as createRemixRequestHandler } from "@remix-run/cloudflare";

/**
* A function that returns the value to use as `context` in route `loader` and
Expand Down Expand Up @@ -37,8 +36,7 @@ export function createRequestHandler({
getLoadContext?: GetLoadContextFunction;
mode?: string;
}) {
let platform: ServerPlatform = {};
let handleRequest = createRemixRequestHandler(build, platform, mode);
let handleRequest = createRemixRequestHandler(build, mode);

return (event: FetchEvent) => {
let loadContext =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { SignFunction, UnsignFunction } from "@remix-run/server-runtime";

const encoder = new TextEncoder();

export async function sign(value: string, secret: string): Promise<string> {
export const sign: SignFunction = async (value, secret) => {
let key = await crypto.subtle.importKey(
"raw",
encoder.encode(secret),
Expand All @@ -19,10 +21,7 @@ export async function sign(value: string, secret: string): Promise<string> {
return value + "." + hash;
}

export async function unsign(
cookie: string,
secret: string
): Promise<string | false> {
export const unsign: UnsignFunction = async (cookie, secret) => {
let key = await crypto.subtle.importKey(
"raw",
encoder.encode(secret),
Expand All @@ -49,4 +48,4 @@ function byteStringToUint8Array(byteString: string): Uint8Array {
}

return array;
}
}
12 changes: 12 additions & 0 deletions packages/remix-cloudflare/globals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// https://stackoverflow.com/a/59499895
export {};

declare global {
interface ProcessEnv {
NODE_ENV: "development" | "production" | "test";
}

interface WorkerGlobalScope {
process: { env: ProcessEnv };
}
}
13 changes: 13 additions & 0 deletions packages/remix-cloudflare/implementations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {
createCookieFactory,
createCookieSessionStorageFactory,
createMemorySessionStorageFactory,
createSessionStorageFactory,
} from "@remix-run/server-runtime";

import { sign, unsign } from "./crypto";

export const createCookie = createCookieFactory({ sign, unsign });
export const createCookieSessionStorage = createCookieSessionStorageFactory(createCookie);
export const createSessionStorage = createSessionStorageFactory(createCookie);
export const createMemorySessionStorage = createMemorySessionStorageFactory(createSessionStorage);
Loading