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
120 changes: 58 additions & 62 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Test

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]
workflow_dispatch:

env:
Expand All @@ -15,21 +15,21 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Install Rust toolchain
shell: bash
run: |
rustup toolchain install ${{ env.RUST_VERSION }} --no-self-update
rustup default ${{ env.RUST_VERSION }}
- name: "Install Wasm Rust target"
run: rustup target add wasm32-wasip1 wasm32-unknown-unknown --toolchain ${{ env.RUST_VERSION }}

- name: Use Node.js 22
uses: actions/setup-node@v3
with:
node-version: 22
- uses: actions/checkout@v3

- name: Install Rust toolchain
shell: bash
run: |
rustup toolchain install ${{ env.RUST_VERSION }} --no-self-update
rustup default ${{ env.RUST_VERSION }}

- name: 'Install Wasm Rust target'
run: rustup target add wasm32-wasip1 wasm32-unknown-unknown --toolchain ${{ env.RUST_VERSION }}

- name: Use Node.js 22
uses: actions/setup-node@v3
with:
node-version: 22

# - name: Install dependencies
# shell: bash
Expand All @@ -39,55 +39,51 @@ jobs:
# shell: bash
# run: npm run fmt-check

- name: Setup `spin`
uses: fermyon/actions/spin/setup@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Run Test
shell: bash
run: |
cd test
./test.sh
- name: Setup `spin`
uses: fermyon/actions/spin/setup@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Run Test
shell: bash
run: |
cd test
./test.sh

test_template:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
router: ['hono', 'itty', 'none']

steps:
- uses: actions/checkout@v3

- name: Use Node.js 22
uses: actions/setup-node@v3
with:
node-version: 22

- name: Setup `spin`
uses: fermyon/actions/spin/setup@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Install templates
run: spin templates install --dir .

- name: Create new project
run: spin new -t http-ts test-project -a

- name: Install dependencies of the test project
run: |
cd test-project
npm install

- name: Add new component to project
run: |
cd test-project
spin add -t http-ts new-component -a
cd new-component
npm install

- name: Build the application
run: |
cd test-project
spin build
- uses: actions/checkout@v3

- name: Use Node.js 22
uses: actions/setup-node@v3
with:
node-version: 22

- name: Setup `spin`
uses: fermyon/actions/spin/setup@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Install templates
run: spin templates install --dir .

- name: Create new project
run: spin new -t http-ts --value http-router=${{ matrix.router }} -a test-project

- name: Add new component to project
run: |
cd test-project
spin add -t http-ts --value http-router=${{ matrix.router }} -a new-component
cd new-component
npm install

- name: Build the application
run: |
cd test-project
spin build
49 changes: 27 additions & 22 deletions templates/http-js/content/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
{
"name": "{{project-name | kebab_case}}",
"version": "1.0.0",
"description": "{{project-description}}",
"main": "index.js",
"scripts": {
"build": "npx webpack && mkdirp dist && j2w -i build/bundle.js -o dist/{{ project-name | kebab_case }}.wasm",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"mkdirp": "^3.0.1",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
},
"dependencies": {
"@spinframework/build-tools": "^1.0.1",
"@spinframework/wasi-http-proxy": "^1.0.0",
"itty-router": "^5.0.18"
}
}
"name": "{{project-name | kebab_case}}",
"version": "1.0.0",
"description": "{{project-description}}",
"main": "index.js",
"scripts": {
"build": "npx webpack && mkdirp dist && j2w -i build/bundle.js -o dist/{{ project-name | kebab_case }}.wasm",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"mkdirp": "^3.0.1",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
},
"dependencies": {
{%- case http-router -%}
{% when "hono" %}
"hono": "^4.7.4",
{% when "itty" %}
"itty-router": "^5.0.18",
{%- endcase %}
"@spinframework/build-tools": "^1.0.1",
"@spinframework/wasi-http-proxy": "^1.0.0"
}
}
15 changes: 0 additions & 15 deletions templates/http-js/content/src/index.js

This file was deleted.

53 changes: 53 additions & 0 deletions templates/http-js/content/src/index.js.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{%- case http-router -%}
{% when "hono" %}
// For Hono documentation refer to https://hono.dev/docs/
import { Hono } from 'hono';
import { logger } from 'hono/logger';

let app = new Hono();

// Logging to stdout via built-in middleware
app.use(logger())

// Example of a custom middleware to set HTTP response header
app.use(async (c, next) => {
c.header('server', 'Spin CLI')
await next();
})

app.get('/', (c) => c.text('Hello, Spin!'));
app.get('/hello/:name', (c) => {
return c.json({ message: `Hello, ${c.req.param('name')}` })
});

app.fire();
{% when "itty" %}
// For AutoRouter documentation refer to https://itty.dev/itty-router/routers/autorouter
import { AutoRouter } from 'itty-router';

let router = AutoRouter();

// Route ordering matters, the first route that matches will be used
// Any route that does not return will be treated as a middleware
// Any unmatched route will return a 404
router
.get('/', () => new Response('Hello, Spin!'))
.get('/hello/:name', ({ name }) => `Hello, ${name}!`)

addEventListener('fetch', (event) => {
event.respondWith(router.fetch(event.request));
});
{% else %}
function handle(_request) {
return new Response('Hello, Spin!', {
status: 200,
headers: {
'content-type': 'text/plain'
}
})
}

addEventListener('fetch', (event) => {
event.respondWith(handle(event.request));
});
{%- endcase %}
5 changes: 5 additions & 0 deletions templates/http-js/metadata/spin-template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ component = "component.txt"
[parameters]
project-description = { type = "string", prompt = "Description", default = "" }
http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" }
http-router = { type = "string", prompt = "HTTP Router", default = "itty", allowed_values = [
"itty",
"hono",
"none",
] }
53 changes: 29 additions & 24 deletions templates/http-ts/content/package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
{
"name": "{{project-name | kebab_case}}",
"version": "1.0.0",
"description": "{{project-description}}",
"main": "index.js",
"scripts": {
"build": "npx webpack && mkdirp dist && j2w -i build/bundle.js -o dist/{{ project-name | kebab_case }}.wasm",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"mkdirp": "^3.0.1",
"ts-loader": "^9.4.1",
"typescript": "^4.8.4",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
},
"dependencies": {
"@spinframework/build-tools": "^1.0.1",
"@spinframework/wasi-http-proxy": "^1.0.0",
"itty-router": "^5.0.18"
}
}
"name": "{{project-name | kebab_case}}",
"version": "1.0.0",
"description": "{{project-description}}",
"main": "index.js",
"scripts": {
"build": "npx webpack && mkdirp dist && j2w -i build/bundle.js -o dist/{{ project-name | kebab_case }}.wasm",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"mkdirp": "^3.0.1",
"ts-loader": "^9.4.1",
"typescript": "^4.8.4",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
},
"dependencies": {
{%- case http-router -%}
{% when "hono" %}
"hono": "^4.7.4",
{% when "itty" %}
"itty-router": "^5.0.18",
{%- endcase %}
"@spinframework/build-tools": "^1.0.1",
"@spinframework/wasi-http-proxy": "^1.0.0"
}
}
16 changes: 0 additions & 16 deletions templates/http-ts/content/src/index.ts

This file was deleted.

Loading