close to final version added the subtaskand comment working section
This commit is contained in:
5
temp_spin/temp/.gitignore
vendored
Normal file
5
temp_spin/temp/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
node_modules
|
||||
dist
|
||||
target
|
||||
.spin/
|
||||
build/
|
||||
14
temp_spin/temp/.vscode/launch.json
vendored
Normal file
14
temp_spin/temp/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "starlingmonkey",
|
||||
"request": "launch",
|
||||
"name": "Debug StarlingMonkey component",
|
||||
"component": "${workspaceFolder}/dist/temp.wasm",
|
||||
"program": "${workspaceFolder}/src/index.js",
|
||||
"stopOnEntry": false,
|
||||
"trace": true
|
||||
}
|
||||
]
|
||||
}
|
||||
12
temp_spin/temp/.vscode/settings.json
vendored
Normal file
12
temp_spin/temp/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"starlingmonkey": {
|
||||
"componentRuntime": {
|
||||
"executable": "spin",
|
||||
"options": [
|
||||
"up",
|
||||
"-f",
|
||||
"${workspaceFolder}",
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
39
temp_spin/temp/README.md
Normal file
39
temp_spin/temp/README.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# `http-js` Template
|
||||
|
||||
A starter template for building JavaScript HTTP applications with Spin.
|
||||
|
||||
## Getting Started
|
||||
|
||||
Build the App
|
||||
|
||||
```bash
|
||||
spin build
|
||||
```
|
||||
|
||||
## Run the App
|
||||
|
||||
```bash
|
||||
spin up
|
||||
```
|
||||
|
||||
## Using Spin Interfaces
|
||||
|
||||
To use additional Spin interfaces, install the corresponding packages:
|
||||
|
||||
| Interface | Package |
|
||||
|---------------|---------------------------------|
|
||||
| Key-Value | `@spinframework/spin-kv` |
|
||||
| LLM | `@spinframework/spin-llm` |
|
||||
| MQTT | `@spinframework/spin-mqtt` |
|
||||
| MySQL | `@spinframework/spin-mysql` |
|
||||
| PostgreSQL | `@spinframework/spin-postgres` |
|
||||
| Redis | `@spinframework/spin-redis` |
|
||||
| SQLite | `@spinframework/spin-sqlite` |
|
||||
| Variables | `@spinframework/spin-variables` |
|
||||
|
||||
## Using the StarlingMonkey Debugger for VS Code
|
||||
|
||||
1. First install the [StarlingMonkey Debugger](https://marketplace.visualstudio.com/items?itemName=BytecodeAlliance.starlingmonkey-debugger) extension.
|
||||
2. Build the component using the debug command `npm run build:debug`.
|
||||
3. Uncomment `tcp://127.0.0.1:*` in the `allowed_outbound_hosts` field in the `spin.toml`.
|
||||
4. Start the debugger in VS Code which should start Spin and attach the debugger. The debugger needs to be restarted for each http call.
|
||||
42
temp_spin/temp/build.mjs
Normal file
42
temp_spin/temp/build.mjs
Normal file
@@ -0,0 +1,42 @@
|
||||
// build.mjs
|
||||
import { build } from 'esbuild';
|
||||
import path from 'path';
|
||||
import { SpinEsbuildPlugin } from "@spinframework/build-tools/plugins/esbuild/index.js";
|
||||
import fs from 'fs';
|
||||
|
||||
const spinPlugin = await SpinEsbuildPlugin();
|
||||
|
||||
// plugin to handle vendor files in node_modules that may not be bundled.
|
||||
// Instead of generating a real source map for these files, it appends a minimal
|
||||
// inline source map pointing to an empty source. This avoids errors and ensures
|
||||
// source maps exist even for unbundled vendor code.
|
||||
let SourceMapPlugin = {
|
||||
name: 'excludeVendorFromSourceMap',
|
||||
setup(build) {
|
||||
build.onLoad({ filter: /node_modules/ }, args => {
|
||||
return {
|
||||
contents: fs.readFileSync(args.path, 'utf8')
|
||||
+ '\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==',
|
||||
loader: 'default',
|
||||
}
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
await build({
|
||||
entryPoints: ['./src/index.js'],
|
||||
outfile: './build/bundle.js',
|
||||
bundle: true,
|
||||
format: 'esm',
|
||||
platform: 'node',
|
||||
sourcemap: true,
|
||||
minify: false,
|
||||
plugins: [spinPlugin, SourceMapPlugin],
|
||||
logLevel: 'error',
|
||||
loader: {
|
||||
'.ts': 'ts',
|
||||
'.tsx': 'tsx',
|
||||
},
|
||||
resolveExtensions: ['.ts', '.tsx', '.js'],
|
||||
sourceRoot: path.resolve(process.cwd(), 'src'),
|
||||
});
|
||||
1710
temp_spin/temp/package-lock.json
generated
Normal file
1710
temp_spin/temp/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
23
temp_spin/temp/package.json
Normal file
23
temp_spin/temp/package.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "temp",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "node build.mjs && mkdirp dist && j2w -i build/bundle.js --initLocation http://temp.localhost -o dist/temp.wasm",
|
||||
"build:debug": "node build.mjs && mkdirp dist && j2w -d -i build/bundle.js --initLocation http://temp.localhost -o dist/temp.wasm",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"mkdirp": "^3.0.1",
|
||||
"esbuild": "^0.25.8"
|
||||
},
|
||||
"dependencies": {
|
||||
"itty-router": "^5.0.18",
|
||||
"@spinframework/build-tools": "^1.0.4",
|
||||
"@spinframework/wasi-http-proxy": "^1.0.0"
|
||||
}
|
||||
}
|
||||
21
temp_spin/temp/spin.toml
Normal file
21
temp_spin/temp/spin.toml
Normal file
@@ -0,0 +1,21 @@
|
||||
spin_manifest_version = 2
|
||||
|
||||
[application]
|
||||
authors = ["tusuii <tusuii764@gmail.com>"]
|
||||
description = ""
|
||||
name = "temp"
|
||||
version = "0.1.0"
|
||||
|
||||
[[trigger.http]]
|
||||
route = "/..."
|
||||
component = "temp"
|
||||
|
||||
[component.temp]
|
||||
source = "dist/temp.wasm"
|
||||
exclude_files = ["**/node_modules"]
|
||||
allowed_outbound_hosts = [
|
||||
# "tcp://127.0.0.1:*", # Uncomment this line to while using the StarlingMonkey Debugger
|
||||
]
|
||||
[component.temp.build]
|
||||
command = ["npm install", "npm run build"]
|
||||
watch = ["src/**/*.js"]
|
||||
17
temp_spin/temp/src/index.js
Normal file
17
temp_spin/temp/src/index.js
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
// 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));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user