Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render webrpcHeader on client and server if enabled #23

Merged
merged 10 commits into from
Oct 22, 2024
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
68 changes: 32 additions & 36 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,42 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Install webrpc-gen
run: |
curl -o ./webrpc-gen -fLJO https://github.com/webrpc/webrpc/releases/download/v0.19.3/webrpc-gen.linux-amd64
chmod +x ./webrpc-gen
echo $PWD >> $GITHUB_PATH
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.20"

# - name: Set up Go
# uses: actions/setup-go@v3
# with:
# go-version: "1.20"
# - name: Install webrpc-gen (development)
# run: git clone --single-branch https://github.com/webrpc/webrpc.git --branch master && cd webrpc && make install
- name: Install webrpc-gen (development)
run: git clone --single-branch https://github.com/webrpc/webrpc.git --branch master && cd webrpc && make install

- name: Regenerate examples
run: cd _examples && make generate

- name: Git diff of regenerated files
run: cd _examples && make diff

webrpc-tests:
strategy:
matrix:
webrpc-version: [v0.14.0]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Set up webrpc binary cache folder
uses: actions/cache@v3
with:
key: webrpc-binaries
path: tests/bin
- name: Install dependencies
run: cd tests && npm install
- name: Download webrpc binaries
run: cd tests && ./download.sh ${{ matrix.webrpc-version }} bin/${{ matrix.webrpc-version }}
- name: Export path of webrpc binaries
run: cd tests && echo "$PWD/bin/${{ matrix.webrpc-version }}" >> $GITHUB_PATH
- name: Run interoperability tests
run: cd tests && ./test.sh
- name: Run typescript check
run: cd tests && npm run ts-check
# webrpc-tests:
# strategy:
# matrix:
# webrpc-version: [v0.14.0]
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-node@v3
# with:
# node-version: 18
# - name: Set up webrpc binary cache folder
# uses: actions/cache@v3
# with:
# key: webrpc-binaries
# path: tests/bin
# - name: Install dependencies
# run: cd tests && npm install
# - name: Download webrpc binaries
# run: cd tests && ./download.sh ${{ matrix.webrpc-version }} bin/${{ matrix.webrpc-version }}
# - name: Export path of webrpc binaries
# run: cd tests && echo "$PWD/bin/${{ matrix.webrpc-version }}" >> $GITHUB_PATH
# - name: Run interoperability tests
# run: cd tests && ./test.sh
# - name: Run typescript check
# run: cd tests && npm run ts-check
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ As you can see, the `-target` supports default `typescript`, any git URI, or a l
### Set custom template variables
Change any of the following values by passing `-option="Value"` CLI flag to `webrpc-gen`.

| webrpc-gen -option | Description | Default value |
|----------------------|----------------------------|----------------------------|
| `-client` | generate client code | unset (`false`) |
| `-server` | generate server code | unset (`false`) |
| webrpc-gen -option | Description | Default value | Version |
|--------------------|----------------------|---------------------------------------------------|---------|
| `-client` | generate client code | unset (`false`) | v0.0.1 |
| `-server` | generate server code | unset (`false`) | v0.0.1 |
| `-webrpcHeader` | `true` | enable client send webrpc version in http headers | v0.15.0 |

## LICENSE

Expand Down
1 change: 1 addition & 0 deletions _examples/node-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.DS_Store
.parcel-cache
4 changes: 2 additions & 2 deletions _examples/node-ts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ bootstrap:
cd webapp && yarn

generate:
webrpc-gen -schema=service.ridl -target=../../ -server -out=./server/server.gen.ts
webrpc-gen -schema=service.ridl -target=../../ -client -out=./webapp/client.gen.ts
webrpc-gen -schema=service.ridl -target=../../../gen-typescript -server -out=./server/server.gen.ts
webrpc-gen -schema=service.ridl -target=../../../gen-typescript -client -out=./webapp/client.gen.ts

run-server:
yarn --cwd ./server start
Expand Down
5 changes: 3 additions & 2 deletions _examples/node-ts/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import express from 'express'
import * as proto from './server.gen'
import { createExampleServiceApp } from './server.gen'
import {createExampleServiceApp, WebrpcHeader} from './server.gen'

const app = express()

app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')
res.setHeader('Access-Control-Allow-Headers', 'Content-Type')
res.setHeader('Access-Control-Allow-Headers', `Content-Type, ${WebrpcHeader}`)
res.setHeader('Access-Control-Expose-Headers', `Content-Type, ${WebrpcHeader}`)

if (req.method === 'OPTIONS') {
res.status(200).end()
Expand Down
10 changes: 5 additions & 5 deletions _examples/node-ts/server/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "node-ts-server",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"express": "^4.16.4"
"express": "^4.21.1"
},
"devDependencies": {
"@types/express": "^4.16.1",
"ts-node": "^8.1.0",
"typescript": "^3.4.3"
"@types/express": "^4.17.21",
"@types/node": "^22.7.7",
"ts-node": "^8.10.2",
"typescript": "^3.9.10"
},
"scripts": {
"start": "./node_modules/.bin/ts-node ."
Expand Down
Loading
Loading