-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
render webrpcHeader on client and server if enabled
- Loading branch information
1 parent
27fa214
commit 8d6b859
Showing
6 changed files
with
179 additions
and
12 deletions.
There are no files selected for viewing
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
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,18 +1,69 @@ | ||
/* eslint-disable */ | ||
// node-ts v1.0.0 bd572b349e330d81cc30b1ff3cf69d7ab59f1619 | ||
// node-ts v1.0.0 6713366104e62b8479d628a193e2a7ca03f37edc | ||
// -- | ||
// Code generated by webrpc-gen@v0.19.3 with ../../ generator. DO NOT EDIT. | ||
// Code generated by webrpc-gen@v0.20.3-1-gf6584bc with ../../ generator. DO NOT EDIT. | ||
// | ||
// webrpc-gen -schema=service.ridl -target=../../ -server -out=./server/server.gen.ts | ||
|
||
export const WebrpcHeader = "Webrpc" | ||
|
||
export const WebrpcHeaderValue = "[email protected];@unknown;[email protected]" | ||
|
||
// WebRPC description and code-gen version | ||
export const WebRPCVersion = "v1" | ||
|
||
// Schema version of your RIDL schema | ||
export const WebRPCSchemaVersion = "v1.0.0" | ||
|
||
// Schema hash generated from your RIDL schema | ||
export const WebRPCSchemaHash = "bd572b349e330d81cc30b1ff3cf69d7ab59f1619" | ||
export const WebRPCSchemaHash = "6713366104e62b8479d628a193e2a7ca03f37edc" | ||
|
||
type WebrpcGenVersions = { | ||
webrpcGenVersion: string; | ||
codeGenName: string; | ||
codeGenVersion: string; | ||
schemaName: string; | ||
schemaVersion: string; | ||
}; | ||
|
||
function versionFromHeader(headers: Headers): WebrpcGenVersions | null { | ||
const headerValue = headers.get(WebrpcHeader); | ||
if (!headerValue) { | ||
throw new Error("header is empty or missing"); | ||
} | ||
|
||
return parseWebrpcGenVersions(headerValue); | ||
} | ||
|
||
function parseWebrpcGenVersions(header: string): WebrpcGenVersions { | ||
const versions = header.split(";"); | ||
if (versions.length < 3) { | ||
throw new Error(`expected at least 3 parts while parsing webrpc header: ${header}`); | ||
} | ||
|
||
const [_, webrpcGenVersion] = versions[0].split("@"); | ||
if (!webrpcGenVersion) { | ||
throw new Error(`webrpc gen version could not be parsed from: ${versions[0]}`); | ||
} | ||
|
||
const [tmplTarget, tmplVersion] = versions[1].split("@"); | ||
if (!tmplTarget || !tmplVersion) { | ||
throw new Error(`tmplTarget and tmplVersion could not be parsed from: ${versions[1]}`); | ||
} | ||
|
||
const [schemaName, schemaVersion] = versions[2].split("@"); | ||
if (!schemaName || !schemaVersion) { | ||
throw new Error(`schema name and schema version could not be parsed from: ${versions[2]}`); | ||
} | ||
|
||
return { | ||
webrpcGenVersion, | ||
codeGenName: tmplTarget, | ||
codeGenVersion: tmplVersion, | ||
schemaName, | ||
schemaVersion, | ||
}; | ||
} | ||
|
||
// | ||
// Types | ||
|
@@ -91,6 +142,8 @@ import express from 'express' | |
app.post('/*', async (req, res) => { | ||
const requestPath = req.baseUrl + req.path | ||
|
||
res.header(WebrpcHeader, WebrpcHeaderValue); | ||
|
||
if (!req.body) { | ||
res.status(400).send("webrpc error: missing body"); | ||
|
||
|
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,18 +1,69 @@ | ||
/* eslint-disable */ | ||
// node-ts v1.0.0 bd572b349e330d81cc30b1ff3cf69d7ab59f1619 | ||
// node-ts v1.0.0 6713366104e62b8479d628a193e2a7ca03f37edc | ||
// -- | ||
// Code generated by webrpc-gen@v0.19.3 with ../../ generator. DO NOT EDIT. | ||
// Code generated by webrpc-gen@v0.20.3-1-gf6584bc with ../../ generator. DO NOT EDIT. | ||
// | ||
// webrpc-gen -schema=service.ridl -target=../../ -client -out=./webapp/client.gen.ts | ||
|
||
export const WebrpcHeader = "Webrpc" | ||
|
||
export const WebrpcHeaderValue = "[email protected];@unknown;[email protected]" | ||
|
||
// WebRPC description and code-gen version | ||
export const WebRPCVersion = "v1" | ||
|
||
// Schema version of your RIDL schema | ||
export const WebRPCSchemaVersion = "v1.0.0" | ||
|
||
// Schema hash generated from your RIDL schema | ||
export const WebRPCSchemaHash = "bd572b349e330d81cc30b1ff3cf69d7ab59f1619" | ||
export const WebRPCSchemaHash = "6713366104e62b8479d628a193e2a7ca03f37edc" | ||
|
||
type WebrpcGenVersions = { | ||
webrpcGenVersion: string; | ||
codeGenName: string; | ||
codeGenVersion: string; | ||
schemaName: string; | ||
schemaVersion: string; | ||
}; | ||
|
||
function versionFromHeader(headers: Headers): WebrpcGenVersions | null { | ||
const headerValue = headers.get(WebrpcHeader); | ||
if (!headerValue) { | ||
throw new Error("header is empty or missing"); | ||
} | ||
|
||
return parseWebrpcGenVersions(headerValue); | ||
} | ||
|
||
function parseWebrpcGenVersions(header: string): WebrpcGenVersions { | ||
const versions = header.split(";"); | ||
if (versions.length < 3) { | ||
throw new Error(`expected at least 3 parts while parsing webrpc header: ${header}`); | ||
} | ||
|
||
const [_, webrpcGenVersion] = versions[0].split("@"); | ||
if (!webrpcGenVersion) { | ||
throw new Error(`webrpc gen version could not be parsed from: ${versions[0]}`); | ||
} | ||
|
||
const [tmplTarget, tmplVersion] = versions[1].split("@"); | ||
if (!tmplTarget || !tmplVersion) { | ||
throw new Error(`tmplTarget and tmplVersion could not be parsed from: ${versions[1]}`); | ||
} | ||
|
||
const [schemaName, schemaVersion] = versions[2].split("@"); | ||
if (!schemaName || !schemaVersion) { | ||
throw new Error(`schema name and schema version could not be parsed from: ${versions[2]}`); | ||
} | ||
|
||
return { | ||
webrpcGenVersion, | ||
codeGenName: tmplTarget, | ||
codeGenVersion: tmplVersion, | ||
schemaName, | ||
schemaVersion, | ||
}; | ||
} | ||
|
||
// | ||
// Types | ||
|
@@ -105,9 +156,12 @@ export class ExampleService implements ExampleService { | |
} | ||
|
||
const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => { | ||
const headers = { ...headers, 'Content-Type': 'application/json' } | ||
headers[WebrpcHeader] = WebrpcHeaderValue | ||
|
||
return { | ||
method: 'POST', | ||
headers: { ...headers, 'Content-Type': 'application/json' }, | ||
headers: headers, | ||
body: JSON.stringify(body || {}), | ||
signal | ||
} | ||
|
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
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
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