Skip to content

Commit 2b7c05d

Browse files
Merge pull request #307 from karthik2804/update_templates
Restructure templates
2 parents a767a41 + 64bde83 commit 2b7c05d

File tree

30 files changed

+80
-50
lines changed

30 files changed

+80
-50
lines changed

templates/http-js/content/.npmrc

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

templates/http-js/content/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44
"description": "{{project-description}}",
55
"main": "index.js",
66
"scripts": {
7-
"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 %}",
7+
"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",
88
"test": "echo \"Error: no test specified\" && exit 1",
9-
"postinstall": "knitwit"
9+
"postinstall": "knitwit --out-dir build/wit/knitwit --out-world combined"
1010
},
1111
"keywords": [],
1212
"author": "",
1313
"license": "ISC",
1414
"devDependencies": {
1515
"mkdirp": "^3.0.1",
1616
"webpack": "^5.74.0",
17-
"webpack-cli": "^4.10.0"
17+
"webpack-cli": "^4.10.0",
18+
"@fermyon/knitwit": "0.3.0"
1819
},
1920
"dependencies": {
20-
"@fermyon/spin-sdk": "^2.3.0"
21+
"@fermyon/spin-sdk": "^2.4.0"
2122
}
2223
}

templates/http-js/content/spin.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ route = "{{http-path}}"
1111
component = "{{project-name | kebab_case}}"
1212

1313
[component.{{project-name | kebab_case}}]
14-
source = "target/{{project-name | kebab_case}}.wasm"
14+
source = "dist/{{project-name | kebab_case}}.wasm"
1515
exclude_files = ["**/node_modules"]
1616
[component.{{project-name | kebab_case}}.build]
17-
command = "npm run build"
17+
command = "npm install && npm run build"
1818
watch = ["src/**/*.ts", "package.json"]
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
import { ResponseBuilder } from "@fermyon/spin-sdk";
1+
import { ResponseBuilder, Router } from "@fermyon/spin-sdk";
2+
3+
let router = Router();
4+
// Modify this route or add additional ones to implement the component's API:
5+
router.get("/hello/:name", (metadata, req, res) => { handleHelloRoute(req, res, metadata.params.name) });
6+
// Default route that will be called for any routes not handled above:
7+
router.all("*", (_, req, res) => { notFound(req, res) });
8+
9+
async function handleHelloRoute(req, res, name) {
10+
res.send(`hello ${name}`);
11+
}
12+
async function notFound(req, res) {
13+
res.status(404);
14+
res.send("not found");
15+
}
216

317
export async function handler(req, res) {
4-
console.log(req);
5-
res.send("hello universe");
18+
await router.handleRequest(req, res);
619
}

templates/http-js/content/webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ module.exports = {
77
outputModule: true,
88
},
99
output: {
10-
path: path.resolve(__dirname, './'),
11-
filename: 'dist.js',
10+
path: path.resolve(__dirname, './build'),
11+
filename: 'bundle.js',
1212
module: true,
1313
library: {
1414
type: "module",

templates/http-js/metadata/snippets/component.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ route = "{{http-path}}"
33
component = "{{project-name | kebab_case}}"
44

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

99
[component.{{project-name | kebab_case}}.build]
10-
command = "npm run build"
10+
command = "npm install && npm run build"
1111
workdir = "{{ output-path }}"

templates/http-js/metadata/spin-template.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ component = "component.txt"
1010
[parameters]
1111
project-description = { type = "string", prompt = "Description", default = "" }
1212
http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" }
13-
enable-aot = { type = "string", prompt = "Enable AoT Compilation [y/N]", default = "N", pattern = "^[yYnN]$" }

templates/http-ts/content/.npmrc

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

0 commit comments

Comments
 (0)