-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7bfcb3
commit 932aeb6
Showing
5 changed files
with
69 additions
and
22 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
server/templates/otoroshi/OTOROSHI_WASM_RESPONSE_TRANSFORMER/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 14 additions & 20 deletions
34
server/templates/otoroshi/OTOROSHI_WASM_ROUTE_MATCHER/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,15 @@ | ||
/* | ||
The "matcher" is a tool that allows filtering a route during the routing phase. | ||
In practice, you can create two routes that are identical from a frontend perspective | ||
but have different "route matchers." | ||
These matchers will select one route or the other based on a specific criterion. | ||
*/ | ||
export function execute() { | ||
let context = JSON.parse(Host.inputString()); | ||
|
||
if (context.request.headers["foo"] === "bar") { | ||
const out = { | ||
result: true | ||
}; | ||
Host.outputString(JSON.stringify(out)); | ||
} else { | ||
const error = { | ||
result: false, | ||
error: { | ||
message: "you're not authorized", | ||
status: 401 | ||
} | ||
}; | ||
Host.outputString(JSON.stringify(error)); | ||
} | ||
|
||
return 0; | ||
} | ||
let context = JSON.parse(Host.inputString()) | ||
|
||
Host.outputString(JSON.stringify({ | ||
result: context.request.headers.foo === "bar" | ||
})) | ||
|
||
return 0 | ||
} |
16 changes: 16 additions & 0 deletions
16
server/templates/otoroshi/OTOROSHI_WASM_ROUTE_MATCHER/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { WasmMatchRouteContext, WasmMatchRouteResponse } from 'otoroshi-ts-types'; | ||
|
||
export declare var Host: any; | ||
|
||
export function execute() { | ||
const context = JSON.parse(Host.inputString()) as WasmMatchRouteContext; | ||
|
||
const out: WasmMatchRouteResponse = { | ||
result: context.request.headers.foo === "bar" | ||
} | ||
|
||
Host.outputString(JSON.stringify(out)); | ||
|
||
return 0; | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
server/templates/otoroshi/OTOROSHI_WASM_ROUTE_MATCHER/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use extism_pdk::*; | ||
use otoroshi_rust_types::types; | ||
|
||
#[plugin_fn] | ||
pub fn execute(Json(context): Json<types::WasmMatchRouteContext>) -> | ||
FnResult<Json<types::WasmMatchRouteResponse>> { | ||
Ok(Json(WasmMatchRouteResponse { | ||
result: context.request.headers.foo === "bar" | ||
})) | ||
} |
27 changes: 27 additions & 0 deletions
27
server/templates/otoroshi/OTOROSHI_WASM_ROUTE_MATCHER/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/buger/jsonparser" | ||
"github.com/extism/go-pdk" | ||
// "github.com/MAIF/otoroshi-go-types" | ||
) | ||
|
||
//export execute | ||
func execute() int32 { | ||
input := pdk.Input() | ||
|
||
var foo, err = jsonparser.GetString(input, "request", "headers", "foo") | ||
|
||
if err != nil { | ||
} | ||
|
||
output := `{ "result": ` + strconv.FormatBool(foo == "bar") + `}` | ||
mem := pdk.AllocateString(output) | ||
pdk.OutputMemory(mem) | ||
|
||
return 0 | ||
} | ||
|
||
func main() {} |