chore: update example for fastly compute@edge (#130)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Yusuke Wada · committed by GitHub · parent 4ed5d47 · Browse files · 6 files·+100 added−55 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+100 added−55 removed
- other:+100 added−55 removed
Provenance
- Commit
6971869- Tree
2c90186- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
GitHub <noreply@github.com>- Parent
4ed5d47
6 files changed+100 added−55 removed
added:examples/compute-at-edge/src/index.ts+22 added
12345678910111213141516171819202122import { Hono } from 'hono'import { basicAuth } from 'hono/basic-auth'import { SHA256 } from 'crypto-js'
const app = new Hono()
app.use( '/auth/*', basicAuth({ username: 'compute', password: 'edge', hashFunction: (m: string) => SHA256(m).toString(), }))
app.get('/', (c) => c.text('Hello! Compute@Edge!'))app.get('/auth/*', (c) => c.text('You are authorized!'))app.get('/hello/:name', (c) => { return c.text(`Hello ${c.req.param('name')}!!!!!`)})
app.fire()added:examples/compute-at-edge/build.js+21 added
123456789101112131415161718192021const { build } = require('esbuild')const globalsPlugin = require('@esbuild-plugins/node-globals-polyfill')const modulesPlugin = require('@esbuild-plugins/node-modules-polyfill')
build({ entryPoints: ['src/index.ts'], bundle: true, minify: true, outfile: 'bin/index.js', platform: 'node', plugins: [ globalsPlugin.NodeGlobalsPolyfillPlugin({ process: true, buffer: true, }), modulesPlugin.NodeModulesPolyfillPlugin(), ],}).catch((error) => { console.error(error) process.exit(1)})deleted:examples/compute-at-edge/index.js-15 removed
123456789101112131415import { Hono } from '../../dist/hono'import { basicAuth } from '../../dist/middleware/basic-auth/basic-auth'
const app = new Hono()
app.use('/auth/*', basicAuth({ username: 'hono', password: 'acoolproject' }))
app.get('/', (c) => c.text('Hono!! Compute@Edge!!'))app.get('/auth/*', (c) => c.text('Your authorized!'))
app.get('/hello/:name', (c) => { return c.text(`Hello ${c.req.param('name')}!!!!!`)})
app.fire()modified:examples/compute-at-edge/package.json+13 added-15 removed
7 unmodified lines8910111213141516171819202122232412262713141516171819202122232425262728297 unmodified lines "type": "git", "url": "https://github.com/yusukebe/hono.git" }, "homepage": "https://github.com/yusukebe/hono", "devDependencies": { "buffer": "^6.0.3", "core-js": "^3.19.1", "crypto-browserify": "^3.12.0", "process": "^0.11.10", "stream-browserify": "^3.0.0", "webpack": "^5.68.0", "webpack-cli": "^4.9.1" }, "dependencies": { "@fastly/js-compute": "^0.2.1", "hono": "*" }, "scripts": { "prebuild": "webpack", "dev": "fastly compute serve", "dev": "fastly compute serve --watch", "prebuild": "node ./build.js", "build": "js-compute-runtime --skip-pkg bin/index.js bin/main.wasm", "deploy": "npm run build && fastly compute deploy" }, "devDependencies": { "@esbuild-plugins/node-globals-polyfill": "^0.1.1", "@esbuild-plugins/node-modules-polyfill": "^0.1.4", "@types/crypto-js": "^4.1.1", "esbuild": "^0.14.25" }, "dependencies": { "@fastly/js-compute": "^0.2.4", "crypto-js": "^4.1.1", "hono": "^0.5.2" }}No newline at end of fileNo newline at end of filemodified:examples/compute-at-edge/README.md+44 added-2 removed
123434567891011121314151617181920212223242526272829303132333435363738394041424344454647# Hono example for Fastly Compute@Edge
```sh$ fastly compute serveThis is an example project with Hono\[炎\] for Fastly Compute@Edge.
## Features
- Minimal- TypeScript- [esbuild](https://github.com/evanw/esbuild) to build- Fast- Live reload- Basic Auth middleware
## Usage
Install
```$ yarn install```
Rename and edit `fastly.toml`
```$ mv fastly.example.toml fastly.toml$ code fastly.toml```
Develop
```$ yarn dev```
Deploy
```$ yarn deploy```
## Author
Yusuke Wada <https://github.com/yusukebe>
## License
MITdeleted:examples/compute-at-edge/webpack.config.js-23 removed
1234567891011121314151617181920212223const path = require('path')
module.exports = { entry: './index.js', optimization: { minimize: true, }, target: ['webworker'], output: { filename: 'index.js', path: path.resolve(__dirname, 'bin'), libraryTarget: 'this', }, resolve: { fallback: { buffer: require.resolve('buffer/'), crypto: require.resolve('crypto-browserify'), stream: require.resolve('stream-browserify'), process: require.resolve('process/browser'), }, }, mode: 'production',}