Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions templates/http-js/content/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
KNITWIT_SOURCE=./config/knitwit.json
9 changes: 5 additions & 4 deletions templates/http-js/content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
"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 {% if enable-aot == 'y' or enable-aot == 'Y' %}--aot{% endif %}",
"build": "npx webpack --mode=production && npx mkdirp dist && npx j2w -i build/bundle.js -d build/wit/knitwit -n combined -o dist/{{project-name | kebab_case}}.wasm",
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "knitwit"
"postinstall": "knitwit --out-dir build/wit/knitwit --out-world combined"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"mkdirp": "^3.0.1",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
"webpack-cli": "^4.10.0",
"@fermyon/knitwit": "0.3.0"
},
"dependencies": {
"@fermyon/spin-sdk": "^2.3.0"
"@fermyon/spin-sdk": "^2.4.0"
}
}
4 changes: 2 additions & 2 deletions templates/http-js/content/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ route = "{{http-path}}"
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
source = "target/{{project-name | kebab_case}}.wasm"
source = "dist/{{project-name | kebab_case}}.wasm"
exclude_files = ["**/node_modules"]
[component.{{project-name | kebab_case}}.build]
command = "npm run build"
command = "npm install && npm run build"
watch = ["src/**/*.ts", "package.json"]
19 changes: 16 additions & 3 deletions templates/http-js/content/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { ResponseBuilder } from "@fermyon/spin-sdk";
import { ResponseBuilder, Router } from "@fermyon/spin-sdk";

let router = Router();
// Modify this route or add additional ones to implement the component's API:
router.get("/hello/:name", (metadata, req, res) => { handleHelloRoute(req, res, metadata.params.name) });
// Default route that will be called for any routes not handled above:
router.all("*", (_, req, res) => { notFound(req, res) });

async function handleHelloRoute(req, res, name) {
res.send(`hello ${name}`);
}
async function notFound(req, res) {
res.status(404);
res.send("not found");
}

export async function handler(req, res) {
console.log(req);
res.send("hello universe");
await router.handleRequest(req, res);
}
4 changes: 2 additions & 2 deletions templates/http-js/content/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module.exports = {
outputModule: true,
},
output: {
path: path.resolve(__dirname, './'),
filename: 'dist.js',
path: path.resolve(__dirname, './build'),
filename: 'bundle.js',
module: true,
library: {
type: "module",
Expand Down
4 changes: 2 additions & 2 deletions templates/http-js/metadata/snippets/component.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ route = "{{http-path}}"
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
source = "{{ output-path }}/target/{{project-name | kebab_case}}.wasm"
source = "{{ output-path }}/dist/{{project-name | kebab_case}}.wasm"
allowed_outbound_hosts = []

[component.{{project-name | kebab_case}}.build]
command = "npm run build"
command = "npm install && npm run build"
workdir = "{{ output-path }}"
1 change: 0 additions & 1 deletion templates/http-js/metadata/spin-template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ component = "component.txt"
[parameters]
project-description = { type = "string", prompt = "Description", default = "" }
http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" }
enable-aot = { type = "string", prompt = "Enable AoT Compilation [y/N]", default = "N", pattern = "^[yYnN]$" }
1 change: 1 addition & 0 deletions templates/http-ts/content/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
KNITWIT_SOURCE=./config/knitwit.json
9 changes: 5 additions & 4 deletions templates/http-ts/content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"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 {% if enable-aot == 'y' or enable-aot == 'Y' %}--aot{% endif %}",
"build": "npx webpack --mode=production && npx mkdirp dist && npx j2w -i build/bundle.js -d build/wit/knitwit -n combined -o dist/{{ project-name | kebab_case }}.wasm",
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "knitwit"
"postinstall": "knitwit --out-dir build/wit/knitwit --out-world combined"
},
"keywords": [],
"author": "",
Expand All @@ -16,9 +16,10 @@
"ts-loader": "^9.4.1",
"typescript": "^4.8.4",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
"webpack-cli": "^4.10.0",
"@fermyon/knitwit": "0.3.0"
},
"dependencies": {
"@fermyon/spin-sdk": "^2.3.0"
"@fermyon/spin-sdk": "^2.4.0"
}
}
4 changes: 2 additions & 2 deletions templates/http-ts/content/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ route = "{{http-path}}"
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
source = "target/{{project-name | kebab_case}}.wasm"
source = "dist/{{project-name | kebab_case}}.wasm"
exclude_files = ["**/node_modules"]
[component.{{project-name | kebab_case}}.build]
command = "npm run build"
command = "npm install && npm run build"
watch = ["src/**/*.ts", "package.json"]
19 changes: 16 additions & 3 deletions templates/http-ts/content/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { ResponseBuilder } from "@fermyon/spin-sdk";
import { ResponseBuilder, Router } from "@fermyon/spin-sdk";

let router = Router();
// Modify this route or add additional ones to implement the component's API:
router.get("/hello/:name", (metadata, req, res) => { handleHelloRoute(req, res, metadata.params.name) });
// Default route that will be called for any routes not handled above:
router.all("*", (_, req, res) => { notFound(req, res) });

async function handleHelloRoute(req: Request, res: ResponseBuilder, name: string) {
res.send(`hello ${name}`);
}
async function notFound(req: Request, res: ResponseBuilder) {
res.status(404);
res.send("not found");
}

export async function handler(req: Request, res: ResponseBuilder) {
console.log(req);
res.send("hello universe");
await router.handleRequest(req, res);
}
4 changes: 2 additions & 2 deletions templates/http-ts/content/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ module.exports = {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
path: path.resolve(__dirname, './'),
filename: 'dist.js',
path: path.resolve(__dirname, './build'),
filename: 'bundle.js',
module: true,
library: {
type: "module",
Expand Down
4 changes: 2 additions & 2 deletions templates/http-ts/metadata/snippets/component.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ route = "{{http-path}}"
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
source = "{{ output-path }}/target/{{project-name | kebab_case}}.wasm"
source = "{{ output-path }}/dist/{{project-name | kebab_case}}.wasm"
allowed_outbound_hosts = []

[component.{{project-name | kebab_case}}.build]
command = "npm run build"
command = "npm install && npm run build"
workdir = "{{ output-path }}"
1 change: 0 additions & 1 deletion templates/http-ts/metadata/spin-template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ component = "component.txt"
[parameters]
project-description = { type = "string", prompt = "Description", default = "" }
http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" }
enable-aot = { type = "string", prompt = "Enable AoT Compilation [y/N]", default = "N", pattern = "^[yYnN]$" }
1 change: 1 addition & 0 deletions templates/redis-js/content/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
KNITWIT_SOURCE=./config/knitwit.json
9 changes: 5 additions & 4 deletions templates/redis-js/content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
"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 {% if enable-aot == 'y' or enable-aot == 'Y' %}--aot{% endif %}",
"build": "npx webpack --mode=production && npx mkdirp dist && npx j2w -i build/bundle.js -d build/wit/knitwit -n combined -o dist/{{project-name | kebab_case}}.wasm",
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "knitwit"
"postinstall": "knitwit --out-dir build/wit/knitwit --out-world combined"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"mkdirp": "^3.0.1",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
"webpack-cli": "^4.10.0",
"@fermyon/knitwit": "0.3.0"
},
"dependencies": {
"@fermyon/spin-sdk": "^2.3.0"
"@fermyon/spin-sdk": "^2.4.0"
}
}
4 changes: 2 additions & 2 deletions templates/redis-js/content/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ channel = "{{redis-channel}}"
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
source = "target/{{project-name | kebab_case}}.wasm"
source = "dist/{{project-name | kebab_case}}.wasm"
exclude_files = ["**/node_modules"]
[component.{{project-name | kebab_case}}.build]
command = "npm run build"
command = "npm install && npm run build"
watch = ["src/**/*.ts", "package.json"]
4 changes: 2 additions & 2 deletions templates/redis-js/content/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module.exports = {
outputModule: true,
},
output: {
path: path.resolve(__dirname, './'),
filename: 'dist.js',
path: path.resolve(__dirname, './build'),
filename: 'bundle.js',
module: true,
library: {
type: "module",
Expand Down
4 changes: 2 additions & 2 deletions templates/redis-js/metadata/snippets/component.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ channel = "{{redis-channel}}"
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
source = "{{ output-path }}/target/{{project-name | kebab_case}}.wasm"
source = "{{ output-path }}/dist/{{project-name | kebab_case}}.wasm"
allowed_outbound_hosts = []
[component.{{project-name | kebab_case}}.build]
command = "npm run build"
command = "npm install && npm run build"
workdir = "{{ output-path }}"
1 change: 0 additions & 1 deletion templates/redis-js/metadata/spin-template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ skip_snippets = ["application_trigger"]
project-description = { type = "string", prompt = "Description", default = "" }
redis-address = { type = "string", prompt = "Redis address", default = "redis://localhost:6379" }
redis-channel = { type = "string", prompt = "Redis channel" }
enable-aot = { type = "string", prompt = "Enable AoT Compilation [y/N]", default = "N", pattern = "^[yYnN]$" }
1 change: 1 addition & 0 deletions templates/redis-ts/content/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
KNITWIT_SOURCE=./config/knitwit.json
9 changes: 5 additions & 4 deletions templates/redis-ts/content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"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 {% if enable-aot == 'y' or enable-aot == 'Y' %}--aot{% endif %}",
"build": "npx webpack --mode=production && npx mkdirp dist && npx j2w -i build/bundle.js -d build/wit/knitwit -n combined -o dist/{{project-name | kebab_case}}.wasm",
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "knitwit"
"postinstall": "knitwit --out-dir build/wit/knitwit --out-world combined"
},
"keywords": [],
"author": "",
Expand All @@ -16,9 +16,10 @@
"ts-loader": "^9.4.1",
"typescript": "^4.8.4",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
"webpack-cli": "^4.10.0",
"@fermyon/knitwit": "0.3.0"
},
"dependencies": {
"@fermyon/spin-sdk": "^2.3.0"
"@fermyon/spin-sdk": "^2.4.0"
}
}
4 changes: 2 additions & 2 deletions templates/redis-ts/content/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ channel = "{{redis-channel}}"
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
source = "target/{{project-name | kebab_case}}.wasm"
source = "dist/{{project-name | kebab_case}}.wasm"
exclude_files = ["**/node_modules"]
[component.{{project-name | kebab_case}}.build]
command = "npm run build"
command = "npm install && npm run build"
watch = ["src/**/*.ts", "package.json"]
4 changes: 2 additions & 2 deletions templates/redis-ts/content/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ module.exports = {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
path: path.resolve(__dirname, './'),
filename: 'dist.js',
path: path.resolve(__dirname, './build'),
filename: 'bundle.js',
module: true,
library: {
type: "module",
Expand Down
4 changes: 2 additions & 2 deletions templates/redis-ts/metadata/snippets/component.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ channel = "{{redis-channel}}"
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
source = "{{ output-path }}/target/{{project-name | kebab_case}}.wasm"
source = "{{ output-path }}/dist/{{project-name | kebab_case}}.wasm"
allowed_outbound_hosts = []
[component.{{project-name | kebab_case}}.build]
command = "npm run build"
command = "npm install && npm run build"
workdir = "{{ output-path }}"
1 change: 0 additions & 1 deletion templates/redis-ts/metadata/spin-template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ skip_snippets = ["application_trigger"]
project-description = { type = "string", prompt = "Description", default = "" }
redis-address = { type = "string", prompt = "Redis address", default = "redis://localhost:6379" }
redis-channel = { type = "string", prompt = "Redis channel" }
enable-aot = { type = "string", prompt = "Enable AoT Compilation [y/N]", default = "N", pattern = "^[yYnN]$" }
Loading