Skip to content

Commit 32e984e

Browse files
committed
update github examples
Signed-off-by: karthik2804 <[email protected]>
1 parent 2b8e9db commit 32e984e

File tree

8 files changed

+3933
-64
lines changed

8 files changed

+3933
-64
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
KNITWIT_SOURCE=./config/knitwit.json

examples/github/octokit-rest/package-lock.json

Lines changed: 3871 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/github/octokit-rest/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"build": "npx webpack --mode=production && npx mkdirp target && npx j2w -i dist.js -n spin-http -o target/octokit-rest.wasm",
7+
"build": "knitwit --out-dir build/wit/knitwit --out-world combined && npx webpack --mode=production && npx mkdirp dist && npx j2w -i build/bundle.js -d build/wit/knitwit -n combined -o dist/octokit-rest.wasm",
88
"test": "echo \"Error: no test specified\" && exit 1"
99
},
1010
"keywords": [],
1111
"author": "",
1212
"license": "ISC",
1313
"devDependencies": {
14+
"@fermyon/knitwit": "0.3.0",
1415
"mkdirp": "^3.0.1",
1516
"ts-loader": "^9.4.1",
1617
"typescript": "^4.8.4",
1718
"webpack": "^5.74.0",
1819
"webpack-cli": "^4.10.0"
1920
},
2021
"dependencies": {
21-
"@fermyon/spin-sdk": "^2.0.0",
22-
"@octokit/rest": "^21.0.0"
22+
"@fermyon/spin-sdk": "^3.0.0-rc1",
23+
"@octokit/rest": "^21.1.0",
24+
"itty-router": "^5.0.18"
2325
}
24-
}
26+
}

examples/github/octokit-rest/spin.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ route = "/..."
1111
component = "octokit-rest"
1212

1313
[component.octokit-rest]
14-
source = "target/octokit-rest.wasm"
14+
source = "dist/octokit-rest.wasm"
1515
exclude_files = ["**/node_modules"]
1616
allowed_outbound_hosts = ["https://api.github.com"]
1717
[component.octokit-rest.build]
18-
command = "npm run build"
19-
watch = ["src/**/*.ts", "package.json"]
18+
command = ["npm install", "npm run build"]
19+
watch = ["src/**/*.ts"]
Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1-
import { ResponseBuilder } from '@fermyon/spin-sdk';
1+
// https://itty.dev/itty-router/routers/autorouter
2+
import { AutoRouter } from 'itty-router';
23
import { Octokit } from '@octokit/rest';
34

45
const octokit = new Octokit();
6+
let router = AutoRouter();
57

6-
export async function handler(_req: Request, res: ResponseBuilder) {
7-
let data = await octokit.rest.repos.listForOrg({
8-
org: 'fermyon',
9-
type: 'public',
10-
});
8+
// Route ordering matters, the first route that matches will be used
9+
// Any route that does not return will be treated as a middleware
10+
// Any unmatched route will return a 404
11+
router
12+
.get("/", async () => {
13+
let data = await octokit.rest.repos.listForOrg({
14+
org: 'fermyon',
15+
type: 'public',
16+
});
17+
return new Response(JSON.stringify(data, null, 2), {
18+
headers: {
19+
"content-type": "application/json"
20+
}
21+
})
22+
})
1123

12-
res.send(JSON.stringify(data, null, 2));
13-
}
24+
//@ts-ignore
25+
addEventListener('fetch', async (event: FetchEvent) => {
26+
event.respondWith(router.fetch(event.request));
27+
});

examples/github/octokit-rest/src/spin.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
const path = require('path');
2-
const SpinSdkPlugin = require('@fermyon/spin-sdk/plugins/webpack');
2+
const SpinSdkPlugin = require("@fermyon/spin-sdk/plugins/webpack")
33

44
module.exports = {
5-
entry: './src/spin.ts',
6-
experiments: {
7-
outputModule: true,
8-
},
9-
module: {
10-
rules: [
11-
{
12-
test: /\.tsx?$/,
13-
use: 'ts-loader',
14-
exclude: /node_modules/,
15-
},
5+
entry: './src/index.ts',
6+
experiments: {
7+
outputModule: true,
8+
},
9+
module: {
10+
rules: [
11+
{
12+
test: /\.tsx?$/,
13+
use: 'ts-loader',
14+
exclude: /node_modules/,
15+
},
16+
],
17+
},
18+
resolve: {
19+
extensions: ['.tsx', '.ts', '.js'],
20+
},
21+
output: {
22+
path: path.resolve(__dirname, './build'),
23+
filename: 'bundle.js',
24+
module: true,
25+
library: {
26+
type: "module",
27+
}
28+
},
29+
plugins: [
30+
new SpinSdkPlugin()
1631
],
17-
},
18-
resolve: {
19-
extensions: ['.tsx', '.ts', '.js'],
20-
},
21-
output: {
22-
path: path.resolve(__dirname, './'),
23-
filename: 'dist.js',
24-
module: true,
25-
library: {
26-
type: 'module',
32+
optimization: {
33+
minimize: false
2734
},
28-
},
29-
plugins: [new SpinSdkPlugin()],
30-
optimization: {
31-
minimize: false,
32-
},
33-
};
35+
};

0 commit comments

Comments
 (0)