Skip to content

Commit

Permalink
feat: add CDN
Browse files Browse the repository at this point in the history
  • Loading branch information
andipaetzold committed Sep 12, 2024
1 parent 032c422 commit e7b5474
Show file tree
Hide file tree
Showing 9 changed files with 5,304 additions and 373 deletions.
5,604 changes: 5,231 additions & 373 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions packages/cdn/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.publish-id
/bin
/pkg
/static-publisher
7 changes: 7 additions & 0 deletions packages/cdn/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Forma36 CDN

The `public` folder is hosted at `cdn.f36.contentful.com`.

## Development

Run `npm run serve` to start the server locally
11 changes: 11 additions & 0 deletions packages/cdn/fastly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file describes a Fastly Compute package. To learn more visit:
# https://developer.fastly.com/reference/fastly-toml/

description = "Forma 36 CDN"
language = "javascript"
manifest_version = 2
name = "@contentful/f36-cdn"

[scripts]
build = "npm run build"

23 changes: 23 additions & 0 deletions packages/cdn/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@contentful/f36-cdn",
"version": "1.0.0",
"private": true,
"description": "Forma 36 CDN",
"type": "module",
"dependencies": {
"@fastly/js-compute": "3.0.0"
},
"devDependencies": {
"@fastly/cli": "10.14.0",
"@fastly/compute-js-static-publish": "6.1.0"
},
"engines": {
"node": ">=20.0.0"
},
"scripts": {
"deploy": "fastly compute deploy",
"prebuild": "npx compute-js-static-publish --build-static",
"build": "js-compute-runtime ./src/index.js ./bin/main.wasm",
"serve": "fastly compute serve"
}
}
Binary file added packages/cdn/public/fonts/geist-mono-1.3.0.woff2
Binary file not shown.
Binary file added packages/cdn/public/fonts/geist-sans-1.3.0.woff2
Binary file not shown.
17 changes: 17 additions & 0 deletions packages/cdn/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// <reference types="@fastly/js-compute" />
import { getServer } from '../static-publisher/statics.js';
const staticContentServer = getServer();

// eslint-disable-next-line no-restricted-globals
addEventListener('fetch', (event) => event.respondWith(handleRequest(event)));
async function handleRequest(event) {
const response = await staticContentServer.serveRequest(event.request);
if (response != null) {
return response;
}

// Do custom things here!
// Handle API requests, serve non-static responses, etc.

return new Response('Not found', { status: 404 });
}
11 changes: 11 additions & 0 deletions packages/cdn/static-publish.rc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @type {import('@fastly/compute-js-static-publish').StaticPublisherConfig} */
const config = {
rootDir: './public',
staticContentRootDir: './static-publisher',
server: {
staticItems: ['/fonts/*'],
},
};

// eslint-disable-next-line import/no-default-export
export default config;

0 comments on commit e7b5474

Please sign in to comment.