# serverless-remix

> AWS Lambda Proxy server request handler for Remix

Latest version **1.1.0** (published 2022-11-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install serverless-remix
pnpm add serverless-remix
yarn add serverless-remix
bun add serverless-remix
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2022-11-14 |
| First published | 2022-05-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 29 |
| Unpacked size | 13.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Anders Quist |
| Maintainers | andqui |

## Links

- npm: https://www.npmjs.com/package/serverless-remix
- Repository: https://github.com/andersquist/serverless-remix
- Homepage: https://github.com/andersquist/serverless-remix#readme
- Issues: https://github.com/andersquist/serverless-remix
- npm.io page: https://npm.io/package/serverless-remix

## Dependencies (29)

- [jest](https://npm.io/package/jest.md) ^27.5.1
- [react](https://npm.io/package/react.md) ^18.2.0
- [eslint](https://npm.io/package/eslint.md) ^8.14.0
- [rimraf](https://npm.io/package/rimraf.md) ^3.0.2
- [rollup](https://npm.io/package/rollup.md) ^2.36.1
- [prettier](https://npm.io/package/prettier.md) ^2.6.2
- [react-dom](https://npm.io/package/react-dom.md) ^18.2.0
- [babel-jest](https://npm.io/package/babel-jest.md) ^27.5.1
- [typescript](https://npm.io/package/typescript.md) ^4.7.4
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.18.6
- [@types/jest](https://npm.io/package/@types/jest.md) ^27.5.2
- [@types/react](https://npm.io/package/@types/react.md) ^18.0.25
- [@remix-run/node](https://npm.io/package/@remix-run/node.md) 1.7.5
- [@types/react-dom](https://npm.io/package/@types/react-dom.md) ^18.0.8
- [react-router-dom](https://npm.io/package/react-router-dom.md) ^6.2.2
- [@babel/preset-env](https://npm.io/package/@babel/preset-env.md) ^7.18.6
- [@types/aws-lambda](https://npm.io/package/@types/aws-lambda.md) ^8.10.82
- [@types/node-fetch](https://npm.io/package/@types/node-fetch.md) ^2.5.7
- [rollup-plugin-copy](https://npm.io/package/rollup-plugin-copy.md) ^3.3.0
- [@babel/preset-react](https://npm.io/package/@babel/preset-react.md) ^7.18.6
- [@rollup/plugin-babel](https://npm.io/package/@rollup/plugin-babel.md) ^5.3.1
- [jest-watch-typeahead](https://npm.io/package/jest-watch-typeahead.md) ^0.6.5
- [@babel/preset-typescript](https://npm.io/package/@babel/preset-typescript.md) ^7.18.6
- [@remix-run/eslint-config](https://npm.io/package/@remix-run/eslint-config.md) 1.7.5
- [jest-watch-select-projects](https://npm.io/package/jest-watch-select-projects.md) ^2.0.0
- [@rollup/plugin-node-resolve](https://npm.io/package/@rollup/plugin-node-resolve.md) ^11.2.1
- [babel-plugin-transform-remove-console](https://npm.io/package/babel-plugin-transform-remove-console.md) ^6.9.4
- [@babel/plugin-proposal-optional-chaining](https://npm.io/package/@babel/plugin-proposal-optional-chaining.md) ^7.18.6
- [@babel/plugin-proposal-export-namespace-from](https://npm.io/package/@babel/plugin-proposal-export-namespace-from.md) ^7.18.6

## Recent versions

- 1.1.0 (latest) — 2022-11-14
- 1.0.0 — 2022-05-01

## README

# Remix Serverless

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

Why? Because it allows you to use REST API Gateway instead of HTTP API Gateway which
the Architect adapter enforces. Furthermore, it enables you to use the Serverless
framework to deploy your web client if that is your preference and also the option
to use the new composite functionality of the Serverless framework along with other
Serverless framework stacks.

## Usage

The current way to get started is to bootstrap a new Remix project with the built in
Architect template and then do some modifications.

Add these dependencies:

```
yarn add remix-serverless
yarn add -D serverless serverless-apigateway-service-proxy serverless-s3-sync
```

Modify the `server.js` file in the root:

```js
import { createRequestHandler } from "remix-serverless";
import * as build from "@remix-run/dev/server-build";

export const handler = createRequestHandler({
  build,
  mode: process.env.NODE_ENV,
  stagePrefix: true,
});
```

The `stagePrefix` is whether you are exposing the site on a subpath, i.e the default
stage path that you get using the REST API Gateway, `dev`, `test` etc.

Modify `remix.config.js` as well:

```js
const { mountRoutes } = require("remix-mount-routes");
const STAGE = "dev";

/**
 * @type {import('@remix-run/dev').AppConfig}
 */
module.exports = {
  serverBuildTarget: "arc",
  server: "./server.js",
  ignoredRouteFiles: ["**/.*"],
  publicPath: `/${STAGE}/_static/build/`,
  routes: (defineRoutes) => {
    return mountRoutes(`/${STAGE}`, "routes");
  },
};
```

The `mountRoutes` and the line with `` publicPath: `/${STAGE}/\_static/build/ `` is only needed if you don't have the site hosted at the root path as mentioned above.

Add a `serverless.yaml` file that looks something like this:

```=yaml
service: remix

frameworkVersion: '3'

plugins:
  - serverless-s3-sync
  - serverless-apigateway-service-proxy

provider:
  name: aws
  runtime: nodejs14.x
  region: eu-north-1

custom:
  s3Sync:
    - bucketNameKey: AssetsBucketKey
      localDir: public
  apiGatewayServiceProxies:
    - s3:
        path: /_static/{path+}
        method: get
        action: GetObject
        bucket:
          Ref: AssetsBucket
        key:
          pathParam: path

package:
  patterns:
    - "!.cache/**"
    - "!public/**"
    - "!app/**"
    - "!server.js"
    - "!yarn.lock"
    - "!remix.*"
    - "!package.json"
    - "!tsconfig.json"
    - "!.eslintrc"
    - "!README.md"

functions:
  server:
    handler: ./server/index.handler
    memorySize: 1152
    timeout: 30
    events:
      - http:
          method: any
          path: /{proxy+}
      - http:
          method: any
          path: /

resources:
  Resources:
    AssetsBucket:
      Type: AWS::S3::Bucket

  Outputs:
    AssetsBucketKey:
      Value: !Ref AssetsBucket
```

To make this work two Serverless plugins are need. The `serverless-s3-sync` for uploading the Remix public assets and the client build output to the asset bucket and `serverless-apigateway-service-proxy` to enable for API Gateway proxy configuration against S3.

After a successful `remix build` with the defaults running `serverless deploy` will upload the artifacts and create the required infrastructure to host the site.

## AWS CDK

This adapter could just as well be used with AWS CDK. Examples to follow.

## Future improvements

Better packaging of the Remix server lambda artifact, `node_modules` that are either `devDependencies` or transient to those are currently deployed as well.

---
_Source: https://npm.io/package/serverless-remix · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
