4.0.0 • Published 4 months ago

@fastly/remix-server-adapter v4.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

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.

4.0.0-beta.0

4 months ago

3.0.0

4 months ago

4.0.0

4 months ago

3.0.0-beta.1

5 months ago

3.0.0-beta.0

10 months ago

2.1.1

5 months ago

2.1.0

6 months ago

2.0.2

11 months ago

2.0.1

11 months ago

2.0.0-beta.0

11 months ago

2.0.0

11 months ago

1.0.0

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.5

1 year ago