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

@h7/hono-fastly-static

v0.2.0

Published

Serve Static Files on Fastly Compute with Hono

Downloads

7

Readme

Hono Static Adapter for Fastly Compute

by Katsuyuki Omuro

@h7/hono-fastly-static is an Adapter for Hono to allow your program to serve static files under Fastly Compute. It leverages the PublisherServer from @fastly/compute-js-static-publish.

Example

import { Hono } from 'hono/quick'
import { serveStatic } from '@h7/hono-fastly-static';
import { getServer } from '../static-publisher/statics.js';

const app = new Hono();

app.get('/', (c) => {
  return c.text('Hello Hono!');
});

const staticPublisherServer = getServer();
app.get('/favicon.ico', serveStatic({ path: './favicon.ico', staticPublisherServer }));
app.get('/static/*', serveStatic({ root: './', staticPublisherServer }));

app.fire();

Usage

Once you have set up a Hono project for Fastly Compute, add this Adapter and the Static Publisher library to your application:

npm install @h7/hono-fastly-static @fastly/compute-js-static-publish

Then, add a static-publish.rc.js file to the root of your application:

/** @type {import('@fastly/compute-js-static-publish').StaticPublisherConfig} */
module.exports = {
  rootDir: './assets',
  staticContentRootDir: './static-publisher',
  excludeDirs: [],
};

This sets up the Static Publisher so that it processes the files under ./assets and makes them available to your Compute program at ./static-publisher/statics.js.

Modify the "prebuild" script under package.json to run compute-js-static-publisher:

{
  "scripts": {
    "prebuild": "compute-js-static-publish --build-static --suppress-framework-warnings && node ./build.js"
  }
}

TIP: Add ./static-publisher/ to your .gitignore as these files will be regenerated on the build.

Finally, modify your application's index.ts file:

  1. Import serveStatic from this library
  2. Import getServer from ../static-publisher/statics.js to instantiate a PublisherServer instance
  3. Call serveStatic, passing it the PublisherServer instance, and use the return value as a Hono Middleware.
import { Hono } from 'hono/quick'
import { serveStatic } from '@h7/hono-fastly-static';
import { getServer } from '../static-publisher/statics.js';

const app = new Hono();

app.get('/', (c) => {
  return c.text('Hello Hono!');
});

const staticPublisherServer = getServer();
app.get('/favicon.ico', serveStatic({ path: './favicon.ico', staticPublisherServer }));
app.get('/static/*', serveStatic({ root: './', staticPublisherServer }));

app.fire();

Run your application locally with npm run dev.

Now, requesting a path such as http://localhost:7676/static/foo.html will serve the static file at ./assets/static/foo.html.

License

MIT.