-
Notifications
You must be signed in to change notification settings - Fork 2
Docs/release 2.0 #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Docs/release 2.0 #75
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
docs/src/content/docs/guides/creating-a-static-manifest.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| --- | ||
| title: Creating a Static Asset Manifest | ||
| description: How to generate a static-asset-manifest for creating Static Servers. | ||
| --- | ||
|
|
||
| Apart from using `npx fastedge-init` to create Static Sites you can also access the built-in tools | ||
| directly. | ||
|
|
||
| `npx fastedge-init` is using this concept under the hood. | ||
|
|
||
| ## Static files | ||
|
|
||
| Because the `wasm` runtime has no concept of a file system we are unable to serve static files in | ||
| the normal manner. | ||
|
|
||
| To solve for this we are able to read files at `compile` time and store them within the wasm binary | ||
| itself as a UintArrayBuffer. | ||
|
|
||
| For this purpose the FastEdge-sdk-js provides a `npx fastedge-assets` command. | ||
|
|
||
| ### fastedge-assets | ||
|
|
||
| This command takes an input folder and an output filename. | ||
|
|
||
| e.g. | ||
|
|
||
| ```sh | ||
| npx fastedge-assets ./public ./src/public-static-assets.ts | ||
| ``` | ||
|
|
||
| It then creates a "Static Assets Manifest" file which is a mapping of all files to include within | ||
| the binary at compile time. (i.e. all files within the `/public` directory) | ||
|
|
||
| Simplified example: | ||
|
|
||
| ```js | ||
| const staticAssetManifest = { | ||
| '/gcore.png': { | ||
| assetKey: '/gcore.png', | ||
| contentType: 'image/png', | ||
| fileInfo: { size: 40261, assetPath: './images/gcore.png' }, | ||
| type: 'wasm-inline', | ||
| }, | ||
| '/home.png': { | ||
| assetKey: '/home.png', | ||
| contentType: 'image/png', | ||
| fileInfo: { size: 1502064, assetPath: './images/home.png' }, | ||
| type: 'wasm-inline', | ||
| }, | ||
| }; | ||
|
|
||
| export { staticAssetManifest }; | ||
| ``` | ||
|
|
||
| This `manifest` can then be consumed by creating a Static Server using: | ||
|
|
||
| ```js | ||
| import { createStaticServer } from '@gcoredev/fastedge-sdk-js'; | ||
|
|
||
| createStaticServer(staticAssetManifest, serverConfig); | ||
| ``` | ||
|
|
||
| Because | ||
| <a href='https://github.com/bytecodealliance/wizer' target='_blank' rel='noopener noreferrer'>wizer</a> | ||
| runs all top-level code before taking a snapshot, you need to ensure that `createStaticServer()` is | ||
| called within the main file at the top level. It cannot be nested in functions or async code that | ||
| may not run during compilation. | ||
|
|
||
| This ensures that `staticAssetManifest` is iterated over and all files read into wasm memory. After | ||
| which `wizer` snapshots the current state, and creates the final wasm binary with all the file | ||
| contents included within the memory at startup. This process ensures there is **NO** start-up delay | ||
| and all files are available at runtime. | ||
|
|
||
| There is a more complete example in our | ||
| <a href='https://github.com/G-Core/FastEdge-examples/blob/main/javascript/README.md' target='_blank' rel='noopener noreferrer'>FastEdge-examples</a> | ||
| repo. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| --- | ||
| title: Version 1.x.x > 2.x.x | ||
| description: Breaking changes in FastEdge-sdk-js@2.0.0 | ||
| --- | ||
|
|
||
| ### Static Asset Servers | ||
|
|
||
| The way Static Asset Manifests are consumed has changed. | ||
|
|
||
| The new version allows for multiple manifests within the same application as well as the ability to | ||
| read file content as a string. | ||
|
|
||
| The easiest way for most people to make this migration is to purely re-run: | ||
|
|
||
| ```sh | ||
| npx fastedge-init | ||
| ``` | ||
|
|
||
| Unless you have custom written code using these functions, the default `static-index.js` should be | ||
| updated automatically for you. | ||
|
|
||
| Version 1: | ||
|
|
||
| ```ts | ||
| import { getStaticServer, createStaticAssetsCache } from '@gcoredev/fastedge-sdk-js'; | ||
| import { staticAssetManifest } from './build/static-server-manifest.js'; | ||
| import { serverConfig } from './build-config.js'; | ||
|
|
||
| const staticAssets = createStaticAssetsCache(staticAssetManifest); | ||
|
|
||
| const staticServer = getStaticServer(serverConfig, staticAssets); | ||
|
|
||
| async function handleRequest(event) { | ||
| const response = await staticServer.serveRequest(event.request); | ||
| if (response != null) { | ||
| return response; | ||
| } | ||
|
|
||
| return new Response('Not found', { status: 404 }); | ||
| } | ||
|
|
||
| addEventListener('fetch', (event) => event.respondWith(handleRequest(event))); | ||
| ``` | ||
|
|
||
| Version 2: | ||
|
|
||
| ```ts | ||
| import { createStaticServer } from '@gcoredev/fastedge-sdk-js'; | ||
| import { staticAssetManifest } from './build/static-asset-manifest.js'; | ||
| import { serverConfig } from './build-config.js'; | ||
|
|
||
| const staticServer = createStaticServer(staticAssetManifest, serverConfig); | ||
|
|
||
| async function handleRequest(event) { | ||
| const response = await staticServer.serveRequest(event.request); | ||
| if (response != null) { | ||
| return response; | ||
| } | ||
|
|
||
| return new Response('Not found', { status: 404 }); | ||
| } | ||
|
|
||
| addEventListener('fetch', (event) => event.respondWith(handleRequest(event))); | ||
| ``` | ||
|
|
||
| :::note[INFO] | ||
|
|
||
| For more examples about the new version see our | ||
| <a href='https://github.com/G-Core/FastEdge-examples/blob/main/javascript/README.md' target='_blank' rel='noopener noreferrer'>FastEdge-examples</a> | ||
| repo. | ||
|
|
||
| ::: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.