npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

serverless-remix

v1.1.0

Published

AWS Lambda Proxy server request handler for Remix

Downloads

4

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:

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:

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:

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.