Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions .eslintrc

This file was deleted.

64 changes: 64 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const OFF = 0;
const WARN = 1;

/** @type {import('eslint').Linter.Config} */
module.exports = {
root: true,
extends: [
require.resolve("@remix-run/eslint-config/internal.js"),
"plugin:markdown/recommended",
],
plugins: ["markdown"],
settings: {
"import/internal-regex": "^~/",
},
overrides: [
{
files: ["**/*.md/**"],
rules: {
"import/no-extraneous-dependencies": OFF,
"no-dupe-keys": OFF,
"no-undef": OFF,
"no-unused-expressions": OFF,
"no-unused-vars": OFF,
"@typescript-eslint/no-redeclare": OFF,
},
},
{
files: ["rollup.config.js"],
rules: {
"import/no-extraneous-dependencies": OFF,
},
},
{
files: [
"**/*.md/*.js?(x)",
"**/*.md/*.ts?(x)",
"integration/helpers/cf-template/**/*.*",
"integration/helpers/deno-template/**/*.*",
"integration/helpers/node-template/**/*.*",
"packages/remix-dev/config/defaults/**/*.*",
"templates/**/*.*",
],
rules: {
"prefer-let/prefer-let": OFF,
"prefer-const": WARN,

"import/order": [
WARN,
{
alphabetize: { caseInsensitive: true, order: "asc" },
groups: ["builtin", "external", "internal", "parent", "sibling"],
"newlines-between": "always",
},
],

"react/jsx-no-leaked-render": [WARN, { validStrategies: ["ternary"] }],
},
},
],
// Report unused `eslint-disable` comments.
reportUnusedDisableDirectives: true,
// Tell ESLint not to ignore dot-files, which are ignored by default.
ignorePatterns: ["!.*.js"],
};
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Remix Serverless
# Serverless Remix

An adapter to use Remix with the Serverless framework as an alternative to the built-in Architect framework adapter that is included with Remix.

Expand Down
11 changes: 11 additions & 0 deletions __tests__/binaryTypes-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { isBinaryType } from "../binaryTypes";

describe("serverkess isBinaryType", () => {
it("should detect binary contentType correctly", () => {
expect(isBinaryType(undefined)).toBe(false);
expect(isBinaryType(null)).toBe(false);
expect(isBinaryType("text/html; charset=utf-8")).toBe(false);
expect(isBinaryType("application/octet-stream")).toBe(true);
expect(isBinaryType("application/octet-stream; charset=test")).toBe(true);
});
});
35 changes: 34 additions & 1 deletion __tests__/server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "../server";

// 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 adapter
// playwright tests do), we just want to test the adapter
jest.mock("@remix-run/node", () => {
let original = jest.requireActual("@remix-run/node");
return {
Expand Down Expand Up @@ -160,6 +160,38 @@ describe("serverless createRequestHandler", () => {
});
});

it("handles root // requests", async () => {
mockedCreateRequestHandler.mockImplementation(() => async (req) => {
return new Response(`URL: ${new URL(req.url).pathname}`);
});

// We don't have a real app to test, but it doesn't matter. We won't ever
// call through to the real createRequestHandler
// @ts-expect-error
await lambdaTester(createRequestHandler({ build: undefined }))
.event(createMockEvent({ path: "//" }))
.expectResolve((res) => {
expect(res.statusCode).toBe(200);
expect(res.body).toBe("URL: //");
});
});

it("handles nested // requests", async () => {
mockedCreateRequestHandler.mockImplementation(() => async (req) => {
return new Response(`URL: ${new URL(req.url).pathname}`);
});

// We don't have a real app to test, but it doesn't matter. We won't ever
// call through to the real createRequestHandler
// @ts-expect-error
await lambdaTester(createRequestHandler({ build: undefined }))
.event(createMockEvent({ path: "//foo//bar" }))
.expectResolve((res) => {
expect(res.statusCode).toBe(200);
expect(res.body).toBe("URL: //foo//bar");
});
});

it("handles null body", async () => {
mockedCreateRequestHandler.mockImplementation(() => async () => {
return new Response(null, { status: 200 });
Expand Down Expand Up @@ -367,6 +399,7 @@ describe("serverless createRemixRequest", () => {
"type": null,
},
Symbol(Request internals): Object {
"credentials": "same-origin",
"headers": Headers {
Symbol(query): Array [
"accept",
Expand Down
7 changes: 5 additions & 2 deletions binaryTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const binaryTypes = [
"font/woff",
"font/woff2",
// Images
"image/avif",
"image/bmp",
"image/gif",
"image/jpeg",
Expand All @@ -33,7 +34,8 @@ const binaryTypes = [
"audio/basic",
"audio/mpeg",
"audio/ogg",
"audio/wavaudio/webm",
"audio/wav",
"audio/webm",
"audio/x-aiff",
"audio/x-midi",
"audio/x-wav",
Expand Down Expand Up @@ -62,5 +64,6 @@ const binaryTypes = [

export function isBinaryType(contentType: string | null | undefined) {
if (!contentType) return false;
return binaryTypes.some((t) => contentType.includes(t));
let [test] = contentType.split(";");
return binaryTypes.includes(test);
}
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
"dist"
],
"dependencies": {
"@babel/core": "^7.18.6",
"@babel/plugin-proposal-export-namespace-from": "^7.18.6",
"@babel/plugin-proposal-optional-chaining": "^7.18.6",
"@babel/preset-env": "^7.18.6",
"@babel/core": "^7.21.8",
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
"@babel/preset-env": "^7.21.5",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@remix-run/eslint-config": "1.7.5",
"@remix-run/node": "1.7.5",
"@babel/preset-typescript": "^7.21.5",
"@remix-run/eslint-config": "1.19.3",
"@remix-run/node": "1.19.3",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-node-resolve": "^11.2.1",
"@types/aws-lambda": "^8.10.82",
Expand All @@ -42,18 +42,18 @@
"@types/react-dom": "^18.0.8",
"babel-jest": "^27.5.1",
"babel-plugin-transform-remove-console": "^6.9.4",
"eslint": "^8.14.0",
"eslint": "^8.23.1",
"jest": "^27.5.1",
"jest-watch-select-projects": "^2.0.0",
"jest-watch-typeahead": "^0.6.5",
"prettier": "^2.6.2",
"prettier": "^2.7.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.2.2",
"rimraf": "^3.0.2",
"rollup": "^2.36.1",
"rollup-plugin-copy": "^3.3.0",
"typescript": "^4.7.4"
"typescript": "^5.0.4"
},
"devDependencies": {
"@commitlint/cli": "^16.2.4",
Expand All @@ -67,6 +67,8 @@
"@types/lambda-tester": "^3.6.1",
"commitizen": "^4.2.5",
"cz-conventional-changelog": "^3.3.0",
"eslint-plugin-markdown": "^2.2.1",
"eslint-plugin-prefer-let": "^3.0.1",
"husky": "^8.0.1",
"is-ci": "^3.0.1",
"lambda-tester": "^4.0.1",
Expand Down
15 changes: 7 additions & 8 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,21 @@ export function createRemixRequest(
event: APIGatewayProxyEvent,
stagePrefix?: boolean
): NodeRequest {
// console.log(event);
console.log(event);
// Either we're exposed on the API Gateway stage path /dev, /prod etc or
// at the root path if using a custom domain
let { path } = stagePrefix ? event.requestContext : event;
let lowerCaseHeaders = Object.fromEntries(
Object.entries(event.headers).map(([k, v]) => [k.toLowerCase(), v])
);
let host = lowerCaseHeaders["x-forwarded-host"] || lowerCaseHeaders.host;
let search = new URLSearchParams(
(event.multiValueQueryStringParameters as any) || {}
).toString();
let search = event.multiValueQueryStringParameters
? `?${new URLSearchParams(
(event.multiValueQueryStringParameters as any) || {}
).toString()}`
: "";
let scheme = process.env.IS_OFFLINE ? "http" : "https";
let url = new URL(
`${path}${search ? "?" + search : ""}`,
`${scheme}://${host}`
);
let url = new URL(`${scheme}://${host}${path}${search}`);
let isFormData = lowerCaseHeaders["content-type"]?.includes(
"multipart/form-data"
);
Expand Down
10 changes: 5 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"include": ["**/*.ts"],
"exclude": ["__tests__", "node_modules", "playground"],
"compilerOptions": {
"lib": ["ES2019", "DOM", "DOM.Iterable"],
"lib": ["ES2019", "DOM.Iterable"],
"target": "ES2019",
"skipLibCheck": true,

"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"strict": true,

"declaration": true,
"emitDeclarationOnly": true,

"outDir": "dist",
"rootDir": "."
"rootDir": ".",
"outDir": "dist"
}
}
Loading