Skip to content

Commit

Permalink
Merge pull request #264 from radu-matei/chore/cleanup-examples
Browse files Browse the repository at this point in the history
  • Loading branch information
radu-matei authored Jul 22, 2024
2 parents 534edb0 + 6af7d32 commit 6f6111f
Show file tree
Hide file tree
Showing 64 changed files with 12,803 additions and 1,002 deletions.
14 changes: 7 additions & 7 deletions examples/typescript/aws/s3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ npm install
- Copy the region, access key ID, secret access key, session token, and bucket name into the code at `src/index.ts`.

```typescript
const client = new SQSClient({
region: "<region>",
const client = new S3Client({
region: "<>",
credentials: {
accessKeyId: "<accessKeyId>",
secretAccessKey: "<secretAccessKey>",
sessionToken: "<sessionToken>"
accessKeyId: "<>>",
secretAccessKey: "<>",
sessionToken: "<>"
},
});

const params = {
Bucket: "<bucketName>"
Bucket: "<>"
};
```

Expand All @@ -50,4 +50,4 @@ spin build
spin up
```

Use e.g. curl -v http://127.0.0.1:3000/ to test the endpoint.
Use e.g. `curl -v http://127.0.0.1:3000/` to test the endpoint.
291 changes: 269 additions & 22 deletions examples/typescript/aws/s3/package-lock.json

Large diffs are not rendered by default.

40 changes: 19 additions & 21 deletions examples/typescript/aws/s3/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import { ResponseBuilder } from "@fermyon/spin-sdk";
const { S3Client, ListObjectsV2Command } = require("@aws-sdk/client-s3");
import { ResponseBuilder } from '@fermyon/spin-sdk';
import { S3Client, ListObjectsV2Command } from '@aws-sdk/client-s3';

const client = new S3Client({
region: "<>",
credentials: {
accessKeyId: "<>>",
secretAccessKey: "<>",
sessionToken: "<>"
},
region: '<>',
credentials: {
accessKeyId: '<>>',
secretAccessKey: '<>',
sessionToken: '<>',
},
});

const params = {
Bucket: "<>"
Bucket: '<>',
};

const command = new ListObjectsV2Command(params);

export async function handler(req: Request, res: ResponseBuilder) {
let data
try {
data = await client.send(command);
res.send(JSON.stringify(data.Contents, null, 2));
} catch (e: any) {
res.status(500)
res.send(`error : ${e.message}`)
}
}
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}`);
}
}
27 changes: 12 additions & 15 deletions examples/typescript/aws/s3/src/spin.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { ResponseBuilder } from "@fermyon/spin-sdk";
import { handler } from ".";
import { ResponseBuilder } from '@fermyon/spin-sdk';
import { handler } from '.';

//@ts-ignore
addEventListener('fetch', (event: FetchEvent) => {
handleEvent(event);
handleEvent(event);
});

async function handleEvent(event: FetchEvent) {

let resolve: any, reject: any;
let responsePromise = new Promise(async (res, rej) => {
resolve = res;
reject = rej;
});
//@ts-ignore
event.respondWith(responsePromise);

let res = new ResponseBuilder(resolve);

await handler(event.request, res)
let resolve: any, reject: any;
let responsePromise = new Promise(async (res, rej) => {
resolve = res;
reject = rej;
});
//@ts-ignore
event.respondWith(responsePromise);
let res = new ResponseBuilder(resolve);
await handler(event.request, res);
}
58 changes: 28 additions & 30 deletions examples/typescript/aws/s3/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
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/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
path: path.resolve(__dirname, './'),
filename: 'dist.js',
module: true,
library: {
type: "module",
}
},
plugins: [
new SpinSdkPlugin()
entry: './src/spin.ts',
experiments: {
outputModule: true,
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
optimization: {
minimize: false
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
path: path.resolve(__dirname, './'),
filename: 'dist.js',
module: true,
library: {
type: 'module',
},
};
},
plugins: [new SpinSdkPlugin()],
optimization: {
minimize: false,
},
};
2 changes: 1 addition & 1 deletion examples/typescript/aws/sqs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ spin build
spin up
```

Use e.g. curl -v http://127.0.0.1:3000/ to test the endpoint.
Use e.g. `curl -v http://127.0.0.1:3000/` to test the endpoint.
Loading

0 comments on commit 6f6111f

Please sign in to comment.