-
Notifications
You must be signed in to change notification settings - Fork 19
(WIP) Update templates/examples for SDK v3 #319
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
karthik2804
merged 12 commits into
spinframework:main
from
karthik2804:update_templates_samples_v3
Jan 28, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1b968f6
bump templates to use v3.0.0-rc1 and depend on itty router directly
karthik2804 374382e
update common pattern examples
karthik2804 3a701a8
update github examples
karthik2804 b13db01
update upstash examples
karthik2804 593d50d
update drizzle example and update tsconfig to be ES2020
karthik2804 1d8dea7
fix outbound url for upstash
karthik2804 dd8eebd
update aws examples
karthik2804 60cc082
update blob-storage
karthik2804 4ae5ae2
update serverlessdb examples
karthik2804 b37b97c
update spin host api examples
karthik2804 2f223d2
update spin package and checkin package-lock for examples
karthik2804 045f9b3
address review comments
karthik2804 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,4 @@ node_modules | |
| dist | ||
| target | ||
| .spin/ | ||
| dist.js | ||
| build/ | ||
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 @@ | ||
| KNITWIT_SOURCE=./config/knitwit.json |
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
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,43 @@ | ||
| import { ResponseBuilder } from '@fermyon/spin-sdk'; | ||
| import { S3Client, ListObjectsV2Command } from '@aws-sdk/client-s3'; | ||
| // https://itty.dev/itty-router/routers/autorouter | ||
| import { AutoRouter } from 'itty-router'; | ||
| import { S3Client, ListObjectsV2Command, GetObjectCommand } from '@aws-sdk/client-s3'; | ||
|
|
||
| const client = new S3Client({ | ||
| region: '<>', | ||
| credentials: { | ||
| accessKeyId: '<>>', | ||
| secretAccessKey: '<>', | ||
| sessionToken: '<>', | ||
| }, | ||
| region: 'us-west-2', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
| credentials: { | ||
| accessKeyId: '<>', | ||
| secretAccessKey: '<>', | ||
| sessionToken: '<>', | ||
| }, | ||
| }); | ||
| let router = AutoRouter(); | ||
|
|
||
| const params = { | ||
| Bucket: '<>', | ||
| }; | ||
| // Route ordering matters, the first route that matches will be used | ||
| // Any route that does not return will be treated as a middleware | ||
| // Any unmatched route will return a 404 | ||
| router | ||
| .get("/list/:bucket", async ({ bucket }) => { | ||
| let command = new ListObjectsV2Command({ Bucket: bucket }); | ||
| try { | ||
| let data = await client.send(command); | ||
| return new Response(JSON.stringify(data.Contents, null, 2)); | ||
| } catch (e: any) { | ||
| return new Response(`error : ${e.message}`, { status: 500 }); | ||
| } | ||
| }) | ||
| .get("/stream/:bucket/:file", async ({ bucket, file }) => { | ||
| let command = new GetObjectCommand({ Bucket: bucket, Key: file }); | ||
| try { | ||
| const data = await client.send(command); | ||
| return new Response(data.Body as ReadableStream, { | ||
| status: 200, | ||
| }); | ||
| } catch (e: any) { | ||
| return new Response(`error : ${e.message}`, { status: 500 }); | ||
| } | ||
| }) | ||
|
|
||
| export async function handler(_req: Request, res: ResponseBuilder) { | ||
| const command = new ListObjectsV2Command(params); | ||
| try { | ||
| let data = await client.send(command); | ||
| res.send(JSON.stringify(data.Contents, null, 2)); | ||
| } catch (e: any) { | ||
| res.status(500); | ||
| res.send(`error : ${e.message}`); | ||
| } | ||
| } | ||
| //@ts-ignore | ||
| addEventListener('fetch', async (event: FetchEvent) => { | ||
| event.respondWith(router.fetch(event.request)); | ||
| }); | ||
This file was deleted.
Oops, something went wrong.
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 |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |
| "jsx": "react", | ||
| "skipLibCheck": true, | ||
| "lib": [ | ||
| "ES2015", | ||
| "ES2020", | ||
| "WebWorker" | ||
| ], | ||
| "allowJs": true, | ||
|
|
||
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 |
|---|---|---|
| @@ -1,33 +1,35 @@ | ||
| const path = require('path'); | ||
| const SpinSdkPlugin = require('@fermyon/spin-sdk/plugins/webpack'); | ||
| const SpinSdkPlugin = require("@fermyon/spin-sdk/plugins/webpack") | ||
|
|
||
| module.exports = { | ||
| entry: './src/spin.ts', | ||
| experiments: { | ||
| outputModule: true, | ||
| }, | ||
| module: { | ||
| rules: [ | ||
| { | ||
| test: /\.tsx?$/, | ||
| use: 'ts-loader', | ||
| exclude: /node_modules/, | ||
| }, | ||
| entry: './src/index.ts', | ||
| experiments: { | ||
| outputModule: true, | ||
| }, | ||
| module: { | ||
| rules: [ | ||
| { | ||
| test: /\.tsx?$/, | ||
| use: 'ts-loader', | ||
| exclude: /node_modules/, | ||
| }, | ||
| ], | ||
| }, | ||
| resolve: { | ||
| extensions: ['.tsx', '.ts', '.js'], | ||
| }, | ||
| output: { | ||
| path: path.resolve(__dirname, './build'), | ||
| filename: 'bundle.js', | ||
| module: true, | ||
| library: { | ||
| type: "module", | ||
| } | ||
| }, | ||
| plugins: [ | ||
| new SpinSdkPlugin() | ||
| ], | ||
| }, | ||
| resolve: { | ||
| extensions: ['.tsx', '.ts', '.js'], | ||
| }, | ||
| output: { | ||
| path: path.resolve(__dirname, './'), | ||
| filename: 'dist.js', | ||
| module: true, | ||
| library: { | ||
| type: 'module', | ||
| optimization: { | ||
| minimize: false | ||
| }, | ||
| }, | ||
| plugins: [new SpinSdkPlugin()], | ||
| optimization: { | ||
| minimize: false, | ||
| }, | ||
| }; |
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 |
|---|---|---|
|
|
@@ -2,4 +2,4 @@ node_modules | |
| dist | ||
| target | ||
| .spin/ | ||
| dist.js | ||
| build/ | ||
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 @@ | ||
| KNITWIT_SOURCE=./config/knitwit.json |
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
File renamed without changes.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good catch - this changed in the example because I rewrote the example to use the router to both be able to list objects and also stream objects for which I hardcoded the region. I will update the readme to use the hardcoded version for now if that is acceptable.