diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3aaa448..aa58f76 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v3 - name: Install webrpc-gen run: | - curl -o ./webrpc-gen -fLJO https://github.com/webrpc/webrpc/releases/download/v0.18.6/webrpc-gen.linux-amd64 + curl -o ./webrpc-gen -fLJO https://github.com/webrpc/webrpc/releases/download/v0.32.3/webrpc-gen.linux-amd64 chmod +x ./webrpc-gen echo $PWD >> $GITHUB_PATH diff --git a/_examples/hello-webrpc/webapp/client.gen.js b/_examples/hello-webrpc/webapp/client.gen.js index 92a2581..c407063 100644 --- a/_examples/hello-webrpc/webapp/client.gen.js +++ b/_examples/hello-webrpc/webapp/client.gen.js @@ -1,6 +1,6 @@ -// hello-webrpc v1.0.0 4fc01b139e8de5a1eb11b0581cd706326a434708 +// hello-webrpc v1.0.0 7037367a376940060eaf2739a920c4dca4a6dc2e // -- -// Code generated by webrpc-gen@v0.18.6 with ../../ generator. DO NOT EDIT. +// Code generated by webrpc-gen@v0.32.3 with ../../ generator. DO NOT EDIT. // // webrpc-gen -schema=hello-api.ridl -target=../../ -exports=false -client -out=./webapp/client.gen.js @@ -11,7 +11,7 @@ const WebRPCVersion = "v1" const WebRPCSchemaVersion = "v1.0.0" // Schema hash generated from your RIDL schema -const WebRPCSchemaHash = "4fc01b139e8de5a1eb11b0581cd706326a434708" +const WebRPCSchemaHash = "7037367a376940060eaf2739a920c4dca4a6dc2e" // // Types diff --git a/client.go.tmpl b/client.go.tmpl index 71d1865..47e7fde 100644 --- a/client.go.tmpl +++ b/client.go.tmpl @@ -1,15 +1,17 @@ {{define "client"}} +{{- $basepath := .BasePath -}} +{{- $services := .Services -}} {{- $opts := .Opts -}} -{{- if .Services}} +{{- if $services }} // // Client // -{{ range .Services}} +{{ range $services }} {{if $opts.exports}}export {{end}}class {{.Name}} { constructor(hostname, fetch) { - this.path = '/rpc/{{.Name}}/' + this.path = '{{$basepath}}{{.Name}}/' this.hostname = hostname this.fetch = (input, init) => fetch(input, init) } diff --git a/main.go.tmpl b/main.go.tmpl index a5cbbc9..ea313df 100644 --- a/main.go.tmpl +++ b/main.go.tmpl @@ -69,10 +69,10 @@ {{template "types" dict "Services" .Services "Types" .Types "Opts" $opts}} {{- if $opts.client}} - {{template "client" dict "Services" .Services "Opts" $opts}} + {{template "client" dict "BasePath" .BasePath "Services" .Services "Opts" $opts}} {{template "client_helpers" .}} {{- end}} {{- if $opts.server}} - {{template "server" dict "Services" .Services "Opts" $opts "TypeMap" $typeMap}} + {{template "server" dict "BasePath" .BasePath "Services" .Services "Opts" $opts "TypeMap" $typeMap}} {{- end}} {{- end}} diff --git a/server.go.tmpl b/server.go.tmpl index e3cca35..68170f9 100644 --- a/server.go.tmpl +++ b/server.go.tmpl @@ -1,5 +1,6 @@ {{define "server"}} +{{- $basepath := .Basepath -}} {{- $services := .Services -}} {{- $typeMap := .TypeMap -}} @@ -37,7 +38,7 @@ import express from 'express' switch(requestPath) { {{range $_, $method := $service.Methods}} - case "/rpc/{{$service.Name}}/{{$method.Name}}": { + case "{{$basepath}}{{$service.Name}}/{{$method.Name}}": { try { {{ range $_, $input := $method.Inputs }} {{- if not $input.Optional}} diff --git a/tests/client.js b/tests/client.js index d9638a6..c3346dc 100644 --- a/tests/client.js +++ b/tests/client.js @@ -174,7 +174,7 @@ export class Complex { export class TestApi { constructor(hostname, fetch) { - this.path = '/rpc/TestApi/' + this.path = '/v1/TestApi/' this.hostname = hostname this.fetch = () => fetch }