-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: karthik2804 <karthik.ganeshram@fermyon.com>
- Loading branch information
1 parent
6b4ba12
commit c533887
Showing
12 changed files
with
159 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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,5 @@ | ||
node_modules | ||
dist | ||
target | ||
.spin/ | ||
dist.js |
This file contains 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,9 @@ | ||
{ | ||
"version": 1, | ||
"project": { | ||
"worlds": [ | ||
"spin-http" | ||
] | ||
}, | ||
"packages": {} | ||
} |
This file contains 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,23 @@ | ||
{ | ||
"name": "{{project-name | kebab_case}}", | ||
"version": "1.0.0", | ||
"description": "{{project-description}}", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "npx webpack --mode=production && npx mkdirp target && npx j2w -i dist.js -d combined-wit -n combined -o target/{{project-name | kebab_case}}.wasm", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"postinstall": "knitwit" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"mkdirp": "^3.0.1", | ||
"webpack": "^5.74.0", | ||
"webpack-cli": "^4.10.0", | ||
"@fermyon/knitwit": "https://github.com/fermyon/knitwit" | ||
}, | ||
"dependencies": { | ||
"@fermyon/spin-sdk": "^2.0.0-alpha.3" | ||
} | ||
} |
This file contains 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,18 @@ | ||
spin_manifest_version = 2 | ||
|
||
[application] | ||
authors = ["{{authors}}"] | ||
description = "{{project-description}}" | ||
name = "{{project-name}}" | ||
version = "0.1.0" | ||
|
||
[[trigger.http]] | ||
route = "{{http-path}}" | ||
component = "{{project-name | kebab_case}}" | ||
|
||
[component.{{project-name | kebab_case}}] | ||
source = "target/{{project-name | kebab_case}}.wasm" | ||
exclude_files = ["**/node_modules"] | ||
[component.{{project-name | kebab_case}}.build] | ||
command = "npm run build" | ||
watch = ["src/**/*.ts", "package.json"] |
This file contains 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,6 @@ | ||
import { ResponseBuilder } from "@fermyon/spin-sdk"; | ||
|
||
export async function handler(req, res) { | ||
console.log(req); | ||
res.send("hello universe"); | ||
} |
This file contains 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,33 @@ | ||
// This file is a wrapper around the actual handler function defined in `index.js` and attaches it to | ||
// the fetchEvent. If you prefer to directly target the fetchEvent, you can | ||
// modify this file | ||
|
||
import { ResponseBuilder } from "@fermyon/spin-sdk"; | ||
import { handler } from "."; | ||
|
||
addEventListener('fetch', (event) => { | ||
handleEvent(event); | ||
}); | ||
|
||
async function handleEvent(event) { | ||
|
||
let resolve, reject; | ||
let responsePromise = new Promise(async (res, rej) => { | ||
resolve = res; | ||
reject = rej; | ||
}); | ||
event.respondWith(responsePromise); | ||
|
||
let res = new ResponseBuilder(resolve); | ||
|
||
try { | ||
// In case you want to do some work after the response is sent | ||
// uncomment the line below and comment out the line with | ||
// await handler(event.request, res) | ||
// event.waitUntil(handler(event.request, res)) | ||
await handler(event.request, res) | ||
} catch (e) { | ||
res.status(500); | ||
res.send(`error in handler: ${e}`); | ||
} | ||
} |
This file contains 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,23 @@ | ||
const path = require('path'); | ||
const SpinSdkPlugin = require("@fermyon/spin-sdk/plugins/webpack") | ||
|
||
module.exports = { | ||
entry: './src/spin.js', | ||
experiments: { | ||
outputModule: true, | ||
}, | ||
output: { | ||
path: path.resolve(__dirname, './'), | ||
filename: 'dist.js', | ||
module: true, | ||
library: { | ||
type: "module", | ||
} | ||
}, | ||
plugins: [ | ||
new SpinSdkPlugin() | ||
], | ||
optimization: { | ||
minimize: false | ||
}, | ||
}; |
This file contains 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,11 @@ | ||
[[trigger.http]] | ||
route = "{{http-path}}" | ||
component = "{{project-name | kebab_case}}" | ||
|
||
[component.{{project-name | kebab_case}}] | ||
source = "{{ output-path }}/target/{{project-name | kebab_case}}.wasm" | ||
allowed_outbound_hosts = [] | ||
|
||
[component.{{project-name | kebab_case}}.build] | ||
command = "npm run build" | ||
workdir = "{{ output-path }}" |
This file contains 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,13 @@ | ||
manifest_version = "1" | ||
id = "http-js" | ||
description = "HTTP request handler using Typescript" | ||
|
||
[add_component] | ||
skip_files = ["spin.toml"] | ||
[add_component.snippets] | ||
component = "component.txt" | ||
|
||
[parameters] | ||
project-description = { type = "string", prompt = "Description", default = "" } | ||
http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" } | ||
# enable-experimental = { type = "string", prompt = "enable experimental interfaces [y/N]", default = "N", pattern = "^[yYnN]$" } |
This file contains 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 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,12 @@ | ||
manifest_version = "1" | ||
id = "http-js" | ||
description = "HTTP request handler using Javascript" | ||
|
||
[add_component] | ||
skip_files = ["spin.toml"] | ||
[add_component.snippets] | ||
component = "component.txt" | ||
|
||
[parameters] | ||
project-description = { type = "string", prompt = "Description", default = "" } | ||
http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" } |