Skip to content

Commit d4ebcbe

Browse files
committed
feat: Add http-hono-ts template
Signed-off-by: Thorsten Hans <[email protected]>
1 parent e5eaa94 commit d4ebcbe

File tree

10 files changed

+162
-0
lines changed

10 files changed

+162
-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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
"ts-loader": "^9.4.1",
16+
"typescript": "^4.8.4",
17+
"webpack": "^5.74.0",
18+
"webpack-cli": "^4.10.0",
19+
"@fermyon/knitwit": "0.3.0"
20+
},
21+
"dependencies": {
22+
"@fermyon/spin-sdk": "^3.0.0",
23+
"hono": "^4.7.4"
24+
}
25+
}
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/**/*.ts"]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// For Hono documentation refer to https://hono.dev/docs/
2+
import { Hono } from 'hono';
3+
import type { Context, Next } from 'hono'
4+
import { logger } from 'hono/logger';
5+
6+
let app = new Hono();
7+
8+
// Logging to stdout via built-in middleware
9+
app.use(logger())
10+
11+
// Example of a custom middleware to set HTTP response header
12+
app.use(async (c: Context, next: Next) => {
13+
c.header('server', 'Spin CLI')
14+
await next();
15+
})
16+
17+
app.get('/', (c: Context) => c.text('Hello, Spin!'));
18+
app.get('/:name', (c: Context) => {
19+
return c.json({ message: `Hello, ${c.req.param('name')}` })
20+
});
21+
22+
app.fire();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "./dist/",
4+
"noImplicitAny": true,
5+
"module": "es6",
6+
"target": "es2020",
7+
"jsx": "react",
8+
"skipLibCheck": true,
9+
"lib": [
10+
"ES2020",
11+
"WebWorker"
12+
],
13+
"allowJs": true,
14+
"strict": true,
15+
"noImplicitReturns": true,
16+
"moduleResolution": "node"
17+
},
18+
"include": [
19+
"src/**/*"
20+
]
21+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const path = require('path');
2+
const SpinSdkPlugin = require("@fermyon/spin-sdk/plugins/webpack")
3+
4+
module.exports = {
5+
entry: './src/index.ts',
6+
experiments: {
7+
outputModule: true,
8+
},
9+
module: {
10+
rules: [
11+
{
12+
test: /\.tsx?$/,
13+
use: 'ts-loader',
14+
exclude: /node_modules/,
15+
},
16+
],
17+
},
18+
resolve: {
19+
extensions: ['.tsx', '.ts', '.js'],
20+
},
21+
output: {
22+
path: path.resolve(__dirname, './build'),
23+
filename: 'bundle.js',
24+
module: true,
25+
library: {
26+
type: "module",
27+
}
28+
},
29+
plugins: [
30+
new SpinSdkPlugin()
31+
],
32+
optimization: {
33+
minimize: false
34+
},
35+
performance: {
36+
hints: false,
37+
}
38+
};
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-ts"
3+
description = "HTTP request handler using TypeScript 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)