Skip to content

Commit 2ed9b5a

Browse files
committed
feat: Add http-hono-js template
Signed-off-by: Thorsten Hans <[email protected]>
1 parent e46342a commit 2ed9b5a

File tree

9 files changed

+126
-0
lines changed

9 files changed

+126
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
target
4+
.spin/
5+
build/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
KNITWIT_SOURCE=./config/knitwit.json
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"version": 1,
3+
"project": {
4+
"worlds": [
5+
"spin-http"
6+
]
7+
},
8+
"packages": {}
9+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "{{project-name | kebab_case}}",
3+
"version": "1.0.0",
4+
"description": "{{project-description}}",
5+
"main": "index.js",
6+
"scripts": {
7+
"build": "knitwit --out-dir build/wit/knitwit --out-world combined && 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",
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"devDependencies": {
14+
"mkdirp": "^3.0.1",
15+
"webpack": "^5.74.0",
16+
"webpack-cli": "^4.10.0",
17+
"@fermyon/knitwit": "0.3.0"
18+
},
19+
"dependencies": {
20+
"@fermyon/spin-sdk": "^3.0.0",
21+
"hono": "^4.7.4"
22+
}
23+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
spin_manifest_version = 2
2+
3+
[application]
4+
authors = ["{{authors}}"]
5+
description = "{{project-description}}"
6+
name = "{{project-name}}"
7+
version = "0.1.0"
8+
9+
[[trigger.http]]
10+
route = "{{http-path}}"
11+
component = "{{project-name | kebab_case}}"
12+
13+
[component.{{project-name | kebab_case}}]
14+
source = "dist/{{project-name | kebab_case}}.wasm"
15+
exclude_files = ["**/node_modules"]
16+
[component.{{project-name | kebab_case}}.build]
17+
command = ["npm install", "npm run build"]
18+
watch = ["src/**/*.js"]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// For Hono documentation refer to https://hono.dev/docs/
2+
import { Hono } from 'hono';
3+
import { logger } from 'hono/logger';
4+
5+
let app = new Hono();
6+
7+
// Logging to stdout via built-in middleware
8+
app.use(logger())
9+
10+
// Example of a custom middleware to set HTTP response header
11+
app.use(async (c, next) => {
12+
c.header('server', 'Spin CLI')
13+
await next();
14+
})
15+
16+
app.get('/', (c) => c.text('Hello, Spin!'));
17+
app.get('/:name', (c) => {
18+
return c.json({ message: `Hello, ${c.req.param('name')}` })
19+
});
20+
21+
app.fire();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const path = require('path');
2+
const SpinSdkPlugin = require("@fermyon/spin-sdk/plugins/webpack")
3+
4+
module.exports = {
5+
entry: './src/index.js',
6+
experiments: {
7+
outputModule: true,
8+
},
9+
output: {
10+
path: path.resolve(__dirname, './build'),
11+
filename: 'bundle.js',
12+
module: true,
13+
library: {
14+
type: "module",
15+
}
16+
},
17+
plugins: [
18+
new SpinSdkPlugin()
19+
],
20+
optimization: {
21+
minimize: false
22+
},
23+
performance: {
24+
hints: false,
25+
}
26+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[[trigger.http]]
2+
route = "{{http-path}}"
3+
component = "{{project-name | kebab_case}}"
4+
5+
[component.{{project-name | kebab_case}}]
6+
source = "{{ output-path }}/dist/{{project-name | kebab_case}}.wasm"
7+
allowed_outbound_hosts = []
8+
9+
[component.{{project-name | kebab_case}}.build]
10+
command = "npm install && npm run build"
11+
workdir = "{{ output-path }}"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
manifest_version = "1"
2+
id = "http-hono-js"
3+
description = "HTTP request handler using JavaScript and Hono"
4+
5+
[add_component]
6+
skip_files = ["spin.toml"]
7+
[add_component.snippets]
8+
component = "component.txt"
9+
10+
[parameters]
11+
project-description = { type = "string", prompt = "Description", default = "" }
12+
http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" }

0 commit comments

Comments
 (0)