@fastly/remix-server-adapter
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

Remix Adapter for Fastly Compute

An adapter that allows the Compute JavaScript entry point program to start Remix. This adapter package we have created is designed to be used with Fastly Compute, and currently uses @fastly/compute-js-static-publish behind the scenes to include resources into the Wasm package bundle.

(@fastly/compute-js-static-publish is set up automatically for you if you set up your Remix project using remix-template.)

Usage

The simplest usage is the createEventHandler function. This function needs to be passed the following parameters:

  • build, obtained by loading /build/index.js
  • server, obtained by calling getServer(), exported from ./statics.js

HINT: ./statics.js is generated automatically by @fastly/compute-js-static-publish.

/// <reference types="@fastly/js-compute" />  
import { createEventHandler } from '@fastly/remix-server-adapter';
import { moduleAssets, getServer } from './statics.js';

/** @type {import('@remix-run/server-runtime').ServerBuild} */
const build = moduleAssets.getAsset('/build/index.js').getStaticModule();

/** @type {import('@fastly/compute-js-static-publish').PublisherServer} */
const server = getServer();

addEventListener("fetch", createEventHandler({ build, server }));

If you need more granular control over the ServerBuild module to use with Remix, or whether/how to handle static assets, you may use the lower-level createRequestHandler and handleAsset functions:

/// <reference types="@fastly/js-compute" />  
import { createRequestHandler, handleAsset } from '@fastly/remix-server-adapter';  
import { moduleAssets, getServer } from './statics.js';

/** @type {import('@remix-run/server-runtime').ServerBuild} */
const build = moduleAssets.getAsset('/build/index.js').getStaticModule();

/** @type {import('@fastly/compute-js-static-publish').PublisherServer} */
const server = getServer();

const requestHandler = createRequestHandler({build});  
 
addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));  
async function handleRequest(event) {  
  let response = await handleAsset(event, build, server);  
 
  if (!response) {  
    response = requestHandler(event);  
  }  
 
  return response;  
}

Issues

If you encounter any non-security-related bug or unexpected behavior, please file an issue using the bug report template.

Security issues

Please see our SECURITY.md for guidance on reporting security-related issues.

License

MIT.

Readme

Keywords

none

Package Sidebar

Install

npm i @fastly/remix-server-adapter

Weekly Downloads

179

Version

4.0.0

License

MIT

Unpacked Size

20.2 kB

Total Files

12

Last publish

Collaborators

  • therealdoramatadora
  • harmony7
  • triblondon