@fastly/compute-js-static-publish 4.0.0-alpha.3 → 4.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -41
- package/build/cli/commands/build-static.d.ts.map +1 -1
- package/build/cli/commands/build-static.js +52 -25
- package/build/server/assets/asset-manager.d.ts +1 -1
- package/build/server/assets/asset-manager.d.ts.map +1 -1
- package/build/server/assets/asset-manager.js +1 -1
- package/build/server/assets/content-assets.js +1 -1
- package/build/server/assets/module-assets.js +1 -1
- package/build/server/object-store/inline-store-entry.js +2 -1
- package/package.json +2 -2
- package/resources/index.js +5 -4
package/README.md
CHANGED
|
@@ -8,16 +8,16 @@ Using a static site generator to build your website? Do you simply need to serve
|
|
|
8
8
|
## New! Version 4
|
|
9
9
|
|
|
10
10
|
Version 4 of this tool has some awesome new features:
|
|
11
|
-
- Support for
|
|
12
|
-
-
|
|
13
|
-
- Brotli and Gzip compression
|
|
14
|
-
- Support for returning `304 Not Modified` status based on `If-None-Match` and `If-Modified-Since` request headers
|
|
15
|
-
- `PublisherServer` class to map incoming requests to asset paths
|
|
16
|
-
-
|
|
17
|
-
- Makes content and metadata available to your application,
|
|
18
|
-
-
|
|
11
|
+
- Support for serving files from Fastly's [Object Store](#object-store) instead of bundling them into the Wasm module.
|
|
12
|
+
- Scaffolded applications no longer use a bundler by default (Webpack is optional).
|
|
13
|
+
- Brotli and Gzip compression.
|
|
14
|
+
- Support for returning `304 Not Modified` status based on `If-None-Match` and `If-Modified-Since` request headers.
|
|
15
|
+
- [`PublisherServer`](#publisherserver) class to map incoming requests to asset paths.
|
|
16
|
+
- Support for publishing files that won't necessarily be served by `PublisherServer`. File contents are made available to your application–useful, e.g., for reading data written by third-party tools, etc.
|
|
17
|
+
- Makes content and metadata available to your application, via pre-package path/file.
|
|
18
|
+
- Support for loading JavaScript files as code into your Compute@Edge application.
|
|
19
19
|
|
|
20
|
-
If you wish to update to this version, you may need to re-scaffold your application, or follow the
|
|
20
|
+
If you wish to update to this version, you may need to re-scaffold your application, or follow the steps outlined in [MIGRATING.md](./MIGRATING.md).
|
|
21
21
|
|
|
22
22
|
## Prerequisites
|
|
23
23
|
|
|
@@ -35,7 +35,7 @@ Assuming the root of your output directory is `./public`,
|
|
|
35
35
|
npx @fastly/compute-js-static-publish@latest --root-dir=./public
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
This will generate a Compute@Edge application at `./compute-js`. It will add a default `./src/index.js` file that instantiates the `PublisherServer` class and runs it to serve the static files from your project.
|
|
38
|
+
This will generate a Compute@Edge application at `./compute-js`. It will add a default `./src/index.js` file that instantiates the [`PublisherServer`](#publisherserver) class and runs it to serve the static files from your project.
|
|
39
39
|
|
|
40
40
|
> This process creates a `./static-publish.rc.js` to hold your configuration. This, as well as the other files created in your new Compute@Edge program at `./compute-js`, can be committed to source control (except for the ones we specify in `.gitignore`!)
|
|
41
41
|
|
|
@@ -65,12 +65,12 @@ Once your application is scaffolded, `@fastly/compute-js-static-publish` integra
|
|
|
65
65
|
running as part of your build process.
|
|
66
66
|
|
|
67
67
|
The files you have configured to be included (`--root-dir`) are enumerated and prepared. Their contents are included into
|
|
68
|
-
your Wasm binary (or made available via Object Store, if so configured). This process is called "publishing".
|
|
68
|
+
your Wasm binary (or made available via [Object Store](#object-store), if so configured). This process is called "publishing".
|
|
69
69
|
|
|
70
70
|
Once the files are published, they are available to the other source files in the Compute@Edge application. For example,
|
|
71
|
-
the stock application
|
|
71
|
+
the stock application runs the [PublisherServer](#publisherserver) class to serve these files.
|
|
72
72
|
|
|
73
|
-
For more advanced uses, such as accessing the contents of these file in your
|
|
73
|
+
For more advanced uses, such as accessing the contents of these file in your application, see the
|
|
74
74
|
[Using the packaged objects in your own application](#using-published-assets-in-your-own-application) section below.
|
|
75
75
|
|
|
76
76
|
Publishing is meant to run each time before building your Compute@Edge application into a Wasm file.
|
|
@@ -79,9 +79,9 @@ If the files in `--root-dir` have changed, then a new set of files will be publi
|
|
|
79
79
|
### Content Compression
|
|
80
80
|
|
|
81
81
|
During publishing, this tool supports pre-compression of content. By default, your assets are compressed using the Brotli
|
|
82
|
-
and gzip algorithms, and then stored alongside the original files in your Wasm
|
|
82
|
+
and gzip algorithms, and then stored alongside the original files in your Wasm binary (or [Object Store](#object-store)).
|
|
83
83
|
|
|
84
|
-
> Note: By default, pre-compressed content assets are not generated when the
|
|
84
|
+
> Note: By default, pre-compressed content assets are not generated when the Object Store is not used.
|
|
85
85
|
This is done to prevent the inclusion multiple of copies of each asset from making the Wasm binary too large.
|
|
86
86
|
If you want to pre-compress assets when not using Object Store, add a value for 'contentCompression' to your
|
|
87
87
|
`static-publish.rc.js` file.
|
|
@@ -125,10 +125,10 @@ Used to populate the `server` key under `static-publish.rc.js`.
|
|
|
125
125
|
|------------------|-------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
126
126
|
| `public-dir` | <root-dir> | The directory that contains your website's public files. |
|
|
127
127
|
| `static-dir` | (None) | Any directories under `--public-dir` that contain the website's static assets that will be served with a very long TTL. You can specify as many such directories as you wish, by listing multiple items. |
|
|
128
|
-
| `auto-ext` | `.html,.htm` |
|
|
129
|
-
| `auto-index` | `index.html,index.htm` |
|
|
130
|
-
| `spa` | (None) |
|
|
131
|
-
| `not-found-page` | `<public-dir>/404.html` |
|
|
128
|
+
| `auto-ext` | `.html,.htm` | Specify automatic file extensions. |
|
|
129
|
+
| `auto-index` | `index.html,index.htm` | Specify filenames for automatically serving an index file. |
|
|
130
|
+
| `spa` | (None) | Path to a fallback file for SPA applications. |
|
|
131
|
+
| `not-found-page` | `<public-dir>/404.html` | Path to a fallback file for 404 Not Found. |
|
|
132
132
|
|
|
133
133
|
See [PublisherServer](#publisherserver) for more information about these features.
|
|
134
134
|
|
|
@@ -140,13 +140,13 @@ Note that the files referenced by `--spa` and `--not-found-page` do not necessar
|
|
|
140
140
|
|
|
141
141
|
These arguments are used to populate the `fastly.toml` and `package.json` files of your Compute@Edge application.
|
|
142
142
|
|
|
143
|
-
| Option | Default | Description
|
|
144
|
-
|
|
145
|
-
| `name` | `name` from `package.json`, or `compute-js-static-site` | The name of your Compute@Edge application.
|
|
146
|
-
| `description` | `description` from `package.json`, or `Compute@Edge static site` | The description of your Compute@Edge application.
|
|
147
|
-
| `author` | `author` from `package.json`, or `you@example.com` | The author of your Compute@Edge application.
|
|
148
|
-
| `service-id` | (None) | The ID of an existing Fastly WASM service for your Compute@Edge application.
|
|
149
|
-
| `object-store-name` | (None) | The name of a Fastly Object Store to hold the content assets. It must be linked to the service specified by `--service-id`. |
|
|
143
|
+
| Option | Default | Description |
|
|
144
|
+
|---------------------|------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
145
|
+
| `name` | `name` from `package.json`, or `compute-js-static-site` | The name of your Compute@Edge application. |
|
|
146
|
+
| `description` | `description` from `package.json`, or `Compute@Edge static site` | The description of your Compute@Edge application. |
|
|
147
|
+
| `author` | `author` from `package.json`, or `you@example.com` | The author of your Compute@Edge application. |
|
|
148
|
+
| `service-id` | (None) | The ID of an existing Fastly WASM service for your Compute@Edge application. |
|
|
149
|
+
| `object-store-name` | (None) | The name of a [Fastly Object Store](https://www.fastly.com/blog/introducing-the-compute-edge-object-store-global-persistent-storage-for-compute-functions) to hold the content assets. It must be linked to the service specified by `--service-id`. |
|
|
150
150
|
|
|
151
151
|
## Usage with frameworks and static site generators
|
|
152
152
|
|
|
@@ -169,12 +169,12 @@ You may still override any of these options individually.
|
|
|
169
169
|
|
|
170
170
|
## PublisherServer
|
|
171
171
|
|
|
172
|
-
|
|
172
|
+
`PublisherServer` is a simple yet powerful server that can be used out of the box to serve the files prepared by this tool.
|
|
173
173
|
|
|
174
174
|
This server handles the following automatically:
|
|
175
175
|
|
|
176
176
|
* Maps the path of your request to a path under `--public-dir` and serves the content of the asset
|
|
177
|
-
* Sources the content from the content packaged in the Wasm, or from the
|
|
177
|
+
* Sources the content from the content packaged in the Wasm binary, or from the [Object Store](#object-store), if configured.
|
|
178
178
|
* Applies long-lived cache headers to files served from `--static-dir` directories. Files under these directories will be cached by the browser for 1 year. (Use versioned or hashed filenames to avoid serving stale assets.)
|
|
179
179
|
* Performs Brotli and gzip compression as requested by the `Accept-Encoding` headers.
|
|
180
180
|
* Provides `Last-Modified` and `ETag` response headers, and uses them with `If-Modified-Since` and `If-None-Match` request headers to produce `304 Not Modified` responses.
|
|
@@ -210,9 +210,9 @@ For `compression`, the following values are allowed:
|
|
|
210
210
|
|
|
211
211
|
## Using the Object Store (BETA) <a name="object-store"></a>
|
|
212
212
|
|
|
213
|
-
Starting v4, it's now possible to upload assets to and serve them from
|
|
213
|
+
Starting with v4, it's now possible to upload assets to and serve them from a [Fastly Object Store](https://www.fastly.com/blog/introducing-the-compute-edge-object-store-global-persistent-storage-for-compute-functions).
|
|
214
214
|
|
|
215
|
-
Fastly Object Store is currently part of a [beta release](https://docs.fastly.com/products/fastly-product-lifecycle#beta),
|
|
215
|
+
Fastly Object Store (globally persistent storage for Compute@Edge applications) is currently part of a [beta release](https://docs.fastly.com/products/fastly-product-lifecycle#beta),
|
|
216
216
|
and to use it you will need to have the feature enabled for your account.
|
|
217
217
|
|
|
218
218
|
To enable the use of Object Store with `@fastly/compute-js-static-publish`, you will need to perform the following steps:
|
|
@@ -221,7 +221,7 @@ To enable the use of Object Store with `@fastly/compute-js-static-publish`, you
|
|
|
221
221
|
compute publish` your application.
|
|
222
222
|
|
|
223
223
|
* Create an Object Store under your Fastly account. At the moment you need to use the Fastly CLI. Once the Object Store
|
|
224
|
-
is created, it must be linked to your Fastly service using the
|
|
224
|
+
is created, it must be linked to your Fastly service using the [Resource API](https://developer.fastly.com/reference/api/services/resource/#create-resource).
|
|
225
225
|
|
|
226
226
|
```shell
|
|
227
227
|
# Create an object store
|
|
@@ -233,9 +233,9 @@ $ curl -i -X POST "https://api.fastly.com/service/YOUR_FASTLY_SERVICE_ID/version
|
|
|
233
233
|
|
|
234
234
|
Object Store API: https://developer.fastly.com/reference/cli/object-store/create/
|
|
235
235
|
|
|
236
|
-
|
|
236
|
+
Resource API: https://developer.fastly.com/reference/api/services/resource/
|
|
237
237
|
|
|
238
|
-
* Once the
|
|
238
|
+
* Once the Object Store is created and linked to your service, add its name to your `static-publish.rc.js`
|
|
239
239
|
file under the `objectStore` key.
|
|
240
240
|
|
|
241
241
|
After you have done the above steps, go ahead and build your application as normal. If you use `fastly compute build --verbose`
|
|
@@ -349,7 +349,7 @@ And that's it! It should be possible to run this task to clean up once in a whil
|
|
|
349
349
|
|
|
350
350
|
> Note that content types are tested at publishing time, not at runtime.
|
|
351
351
|
|
|
352
|
-
* `server` - Configuration of `PublisherServer()
|
|
352
|
+
* `server` - [Configuration of `PublisherServer()`](#configuring-publisherserver).
|
|
353
353
|
above.
|
|
354
354
|
|
|
355
355
|
### Running custom code alongside Publisher Server
|
|
@@ -358,22 +358,23 @@ The generated `./src/index.js` program instantiates the server and simply asks i
|
|
|
358
358
|
|
|
359
359
|
You are free to add code to this file.
|
|
360
360
|
|
|
361
|
-
For example, if the
|
|
362
|
-
own code to handle these cases, such as to provide custom responses.
|
|
361
|
+
For example, if the `PublisherServer` is unable to formulate a response to the request, then it returns `null`. You may
|
|
362
|
+
add your own code to handle these cases, such as to provide custom responses.
|
|
363
363
|
|
|
364
364
|
```js
|
|
365
365
|
import { getServer } from './statics.js';
|
|
366
|
-
const
|
|
366
|
+
const staticContentServer = getServer();
|
|
367
367
|
|
|
368
368
|
addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));
|
|
369
369
|
async function handleRequest(event) {
|
|
370
370
|
|
|
371
|
-
const response = await
|
|
371
|
+
const response = await staticContentServer.serveRequest(event.request);
|
|
372
372
|
if (response != null) {
|
|
373
373
|
return response;
|
|
374
374
|
}
|
|
375
375
|
|
|
376
376
|
// Do custom things here!
|
|
377
|
+
// Handle API requests, serve non-static responses, etc.
|
|
377
378
|
|
|
378
379
|
return new Response('Not found', { status: 404 });
|
|
379
380
|
}
|
|
@@ -385,7 +386,7 @@ Publishing, as described earlier, is the process of preparing files for inclusio
|
|
|
385
386
|
This process also makes metadata available about each of the files that are included, such as its content type, the last
|
|
386
387
|
modified date, the file hash, and so on.
|
|
387
388
|
|
|
388
|
-
The `PublisherServer` class
|
|
389
|
+
The [`PublisherServer` class](#publisherserver) used by the default scaffolded application is a simple application of this content
|
|
389
390
|
and metadata. By importing `./statics.js` into your Compute@Edge application, you can just as easily access this
|
|
390
391
|
information about the assets that were included during publishing.
|
|
391
392
|
|
|
@@ -516,8 +517,8 @@ See the definition of `ContentAssetMetadataMapEntry` in the [`types/content-asse
|
|
|
516
517
|
|
|
517
518
|
### Using Webpack
|
|
518
519
|
|
|
519
|
-
As of v4, Webpack is no longer required, and
|
|
520
|
-
If you wish to use some features of Webpack, you
|
|
520
|
+
As of v4, Webpack is no longer required, and is no longer part of the default scaffolded application.
|
|
521
|
+
If you wish to use some features of Webpack, you may include Webpack in your generated application by specifying
|
|
521
522
|
`--webpack` at the command line.
|
|
522
523
|
|
|
523
524
|
## Migrating
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-static.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/build-static.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build-static.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/build-static.ts"],"names":[],"mappings":"AA+DA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AA6IhD,wBAAsB,iBAAiB,CAAC,iBAAiB,EAAE,eAAe,CAAC,kBAAkB,iBAoe5F"}
|
|
@@ -2,33 +2,60 @@
|
|
|
2
2
|
// public folder to be served.
|
|
3
3
|
// e.g., with create-react-app, this would be the ./build directory.
|
|
4
4
|
// Outputs:
|
|
5
|
+
//
|
|
5
6
|
// statics-metadata.js
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
// -
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
7
|
+
//
|
|
8
|
+
// objectStoreName: string - Name of object store, or null if not used.
|
|
9
|
+
// contentAssetMetadataMap: Map<string, ContentAssetMetadataMapEntry> - mapping of asset keys to their metadata
|
|
10
|
+
// - key: string - assetKey, the filename relative to root dir (e.g., /public/foo/index.html)
|
|
11
|
+
// - value: ContentAssetMetadataMapEntry - metadata for asset
|
|
12
|
+
//
|
|
13
|
+
// ContentAssetMetadataMapEntry structure
|
|
14
|
+
// - assetKey: string - filename relative to root dir
|
|
15
|
+
// - contentType: string - MIME type
|
|
16
|
+
// - text: boolean - whether this is a text file
|
|
17
|
+
// - lastModifiedTime: number - last modified time as unix time (seconds)
|
|
18
|
+
// - fileInfo: FileInfo - information about the file
|
|
19
|
+
// - compressedFileInfos: Map<string, FileInfo> - information about any compressed versions
|
|
20
|
+
// - key: string - compression algorithm name (e.g., "gzip", "br", etc.)
|
|
21
|
+
// - value: FileInfo - information about the compressed version of the file
|
|
22
|
+
// - isInline: boolean - whether this file is "inline". If false, object is in the object store.
|
|
23
|
+
// FileInfo structure
|
|
24
|
+
// - hash: string - SHA-256 hash of file
|
|
25
|
+
// - size: number - file size in bytes
|
|
26
|
+
// - staticFilePath: string - path to file in local filesystem, relative to root dir
|
|
27
|
+
// - objectStoreKey: string - object store key, present only for items in object store
|
|
28
|
+
//
|
|
15
29
|
// statics.js
|
|
16
|
-
// imports statics-metadata.js and adds utilities
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
30
|
+
// imports statics-metadata.js and adds utilities for working with the content assets, as well as
|
|
31
|
+
// for loading module assets. Also gives access to StaticPublisher and its config.
|
|
32
|
+
// See README.md for details
|
|
33
|
+
//
|
|
34
|
+
// moduleAssetMap: Map<string, ModuleAssetMapEntry>
|
|
35
|
+
// - key: string - assetKey, the filename relative to root dir (e.g., /module/hello.js)
|
|
36
|
+
// - value: ModuleAssetMapEntry - information about the module
|
|
37
|
+
//
|
|
38
|
+
// ModuleAssetMapEntry structure
|
|
39
|
+
// - isStaticImport: boolean - if true, then uses a static import statement to load the module
|
|
40
|
+
// - if false, then module is loaded when getModule is called
|
|
41
|
+
// - module: any - the statically loaded module if isStaticImport is true, or null
|
|
42
|
+
// - loadModule: function - a function that dynamically loads the module and returns it, if isStaticImport is false, or null
|
|
43
|
+
//
|
|
44
|
+
// contentAssets: ContentAssets instance
|
|
45
|
+
// moduleAssets: ModuleAssets instance
|
|
46
|
+
//
|
|
47
|
+
// getServer(): function - instantiates PublisherServer singleton and returns it
|
|
48
|
+
// serverConfig: PublisherServerConfigNormalized - publisher server config settings
|
|
49
|
+
//
|
|
50
|
+
// PublisherServerConfigNormalized structure
|
|
51
|
+
// - publicDirPrefix: string
|
|
52
|
+
// - staticItems: string[]
|
|
53
|
+
// - compression: string[]
|
|
54
|
+
// - spaFile: string or null
|
|
55
|
+
// - notFoundPageFile: string or null
|
|
56
|
+
// - autoExt: string[]
|
|
57
|
+
// - autoIndex: string[]
|
|
58
|
+
//
|
|
32
59
|
import * as fs from "fs";
|
|
33
60
|
import * as path from "path";
|
|
34
61
|
import * as url from "url";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare abstract class AssetManager<TAsset> {
|
|
2
2
|
protected readonly assets: Record<string, TAsset>;
|
|
3
3
|
protected constructor();
|
|
4
|
-
|
|
4
|
+
protected initAsset(assetKey: string, asset: TAsset): void;
|
|
5
5
|
getAsset(assetKey: string): TAsset | null;
|
|
6
6
|
}
|
|
7
7
|
//# sourceMappingURL=asset-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset-manager.d.ts","sourceRoot":"","sources":["../../../src/server/assets/asset-manager.ts"],"names":[],"mappings":"AAAA,8BAAsB,YAAY,CAAC,MAAM;IAEvC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAElD,SAAS;IAIT,
|
|
1
|
+
{"version":3,"file":"asset-manager.d.ts","sourceRoot":"","sources":["../../../src/server/assets/asset-manager.ts"],"names":[],"mappings":"AAAA,8BAAsB,YAAY,CAAC,MAAM;IAEvC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAElD,SAAS;IAIT,SAAS,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAInD,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;CAI1C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// A class designed to give a Body-style interface to Uint8Array.
|
|
2
2
|
// The intended use case is arrays brought in from includeBytes().
|
|
3
|
-
|
|
3
|
+
class InlineStoreEntry {
|
|
4
4
|
constructor(array, contentEncoding, hash, size) {
|
|
5
5
|
this._body = new ReadableStreamForBytes(array);
|
|
6
6
|
this._consumed = false;
|
|
@@ -63,6 +63,7 @@ export class InlineStoreEntry {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
InlineStoreEntry.decoder = new TextDecoder();
|
|
66
|
+
export { InlineStoreEntry };
|
|
66
67
|
class ReadableStreamForBytes extends ReadableStream {
|
|
67
68
|
constructor(array) {
|
|
68
69
|
super({
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastly/compute-js-static-publish",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.0-alpha.
|
|
4
|
+
"version": "4.0.0-alpha.4",
|
|
5
5
|
"description": "Static Publisher for Compute@Edge JavaScript",
|
|
6
6
|
"main": "./build/index.js",
|
|
7
7
|
"types": "./build/index.d.ts",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@types/glob-to-regexp": "^0.4.1",
|
|
41
41
|
"@types/node": "^18.0.0",
|
|
42
42
|
"rimraf": "^4.3.0",
|
|
43
|
-
"typescript": "^
|
|
43
|
+
"typescript": "^5.0.2"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=18"
|
package/resources/index.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
/// <reference types="@fastly/js-compute" />
|
|
2
|
-
|
|
3
2
|
import { getServer } from './statics.js';
|
|
4
|
-
const
|
|
3
|
+
const staticContentServer = getServer();
|
|
5
4
|
|
|
6
5
|
// eslint-disable-next-line no-restricted-globals
|
|
7
6
|
addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));
|
|
8
7
|
async function handleRequest(event) {
|
|
9
8
|
|
|
10
|
-
const response = await
|
|
11
|
-
|
|
9
|
+
const response = await staticContentServer.serveRequest(event.request);
|
|
12
10
|
if (response != null) {
|
|
13
11
|
return response;
|
|
14
12
|
}
|
|
15
13
|
|
|
14
|
+
// Do custom things here!
|
|
15
|
+
// Handle API requests, serve non-static responses, etc.
|
|
16
|
+
|
|
16
17
|
return new Response('Not found', { status: 404 });
|
|
17
18
|
}
|