Skip to content

Commit ac935ab

Browse files
committed
first commit
0 parents  commit ac935ab

35 files changed

+19771
-0
lines changed

Dockerfile-client

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM node:18-alpine3.15 as build
2+
3+
RUN apk add --no-cache protoc
4+
5+
WORKDIR /app
6+
7+
ENV protoc_gen_grpc_web=./node_modules/.bin/protoc-gen-grpc-web
8+
9+
COPY ./client/package.json .
10+
COPY ./client/yarn.lock .
11+
COPY ./proto/greeting.proto .
12+
13+
RUN yarn install
14+
15+
RUN mkdir -p ./src/proto
16+
RUN protoc -I=. greeting.proto \
17+
--plugin=protoc-gen-grpc-web=${protoc_gen_grpc_web} \
18+
--js_out=import_style=commonjs:./src \
19+
--grpc-web_out=import_style=typescript,mode=grpcwebtext:./src
20+
21+
22+
COPY ./client .
23+
24+
EXPOSE 8081
25+
CMD ["yarn", "start"]docker

Dockerfile-envoy

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM alpine:3.15.1 AS build
2+
3+
WORKDIR /app
4+
5+
RUN apk add --no-cache protoc
6+
7+
COPY ./proto/greeting.proto .
8+
9+
# build proto descriptor
10+
RUN protoc --include_imports --include_source_info \
11+
--descriptor_set_out=greeting.pb greeting.proto
12+
13+
FROM envoyproxy/envoy:v1.22.0
14+
15+
COPY --from=build /app/greeting.pb /tmp/

Dockerfile-server

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM node:16.14.2-alpine3.15
2+
3+
WORKDIR /app
4+
5+
COPY package.json .
6+
COPY package-lock.json .
7+
8+
RUN npm install
9+
10+
COPY ./proto/greeting.proto .
11+
COPY /server/server.js .
12+
13+
ENTRYPOINT ["node", "server.js"]

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Run
2+
3+
This is an example repo to call a grpc service from a react client, inspired by [this this repo](https://github.com/norbjd/grpc-web-nginx-envoy)
4+
5+
To run the stack, just run:
6+
7+
```
8+
docker-compose build
9+
docker-compose up
10+
```
11+
12+
Then, in a browser, open [`http://localhost:8081`](http://localhost:8081) (the client using gRPC-web to call Envoy).
13+
14+
Enter a name in the input and you should see:
15+
16+
```
17+
Hello {entered_name}!
18+
```
19+
20+
I'm using create-react-app with typescript and grpc-web, grpc & proto generated with bellow command in the root:
21+
22+
```
23+
./proto-gen.sh
24+
```

client/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

client/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
EXTEND_ESLINT=true

client/.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

client/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Getting Started with Create React App
2+
3+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4+
5+
## Available Scripts
6+
7+
In the project directory, you can run:
8+
9+
### `npm start`
10+
11+
Runs the app in the development mode.\
12+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
13+
14+
The page will reload if you make edits.\
15+
You will also see any lint errors in the console.
16+
17+
### `npm test`
18+
19+
Launches the test runner in the interactive watch mode.\
20+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21+
22+
### `npm run build`
23+
24+
Builds the app for production to the `build` folder.\
25+
It correctly bundles React in production mode and optimizes the build for the best performance.
26+
27+
The build is minified and the filenames include the hashes.\
28+
Your app is ready to be deployed!
29+
30+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31+
32+
### `npm run eject`
33+
34+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
35+
36+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37+
38+
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
39+
40+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
41+
42+
## Learn More
43+
44+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45+
46+
To learn React, check out the [React documentation](https://reactjs.org/).

client/package.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "client",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@testing-library/jest-dom": "^5.16.5",
7+
"@testing-library/react": "^13.4.0",
8+
"@testing-library/user-event": "^13.5.0",
9+
"@types/jest": "^27.5.2",
10+
"@types/node": "^16.18.9",
11+
"@types/react": "^18.0.26",
12+
"@types/react-dom": "^18.0.9",
13+
"google-protobuf": "^3.21.2",
14+
"grpc-web": "^1.4.2",
15+
"protoc-gen-grpc-web": "^1.4.1",
16+
"react": "^18.2.0",
17+
"react-dom": "^18.2.0",
18+
"react-scripts": "5.0.1",
19+
"typescript": "^4.9.4",
20+
"web-vitals": "^2.1.4"
21+
},
22+
"scripts": {
23+
"start": "PORT=8081 react-scripts start",
24+
"build": "react-scripts build",
25+
"test": "react-scripts test",
26+
"eject": "react-scripts eject"
27+
},
28+
"eslintConfig": {
29+
"extends": [
30+
"react-app",
31+
"react-app/jest"
32+
],
33+
"ignorePatterns": [
34+
"**/*_pb.js"
35+
]
36+
},
37+
"browserslist": {
38+
"production": [
39+
">0.2%",
40+
"not dead",
41+
"not op_mini all"
42+
],
43+
"development": [
44+
"last 1 chrome version",
45+
"last 1 firefox version",
46+
"last 1 safari version"
47+
]
48+
}
49+
}

client/public/favicon.ico

3.78 KB
Binary file not shown.

0 commit comments

Comments
 (0)