mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
60db6e1d51025c8898c331c3986d8dbf45027887
MicroServices Gateway / API Gateway
First things first, register an app:
curl -H "Content-Type: application/json" -X POST -d '{"name":"myapp","password":"xyz"}' http://localhost:8080/test/1/projects/123/apps
Now add routes to the app. First we'll add a route to the output of a docker container:
curl -H "Content-Type: application/json" -X POST -d '{"path":"/hello.rb","image":"treeder/hello.rb", "type":"run"}' http://localhost:8080/test/1/projects/123/apps/myapp/routes
curl -H "Content-Type: application/json" -X POST -d '{"path":"/helloiron","image":"iron/hello", "type":"run"}' http://localhost:8080/test/1/projects/123/apps/myapp/routes
Test out the route:
curl -i -X GET http://localhost:8080/hello.rb?app=myapp
Now try mapping an app endpoint:
curl -H "Content-Type: application/json" -X POST -d '{"path":"/sinatra","image":"treeder/hello-sinatra", "type":"app", "cpath":"/"}' http://localhost:8080/test/1/projects/123/apps/myapp/routes
And test it out:
curl -i -X GET http://localhost:8080/sinatra?app=myapp
And another:
curl -H "Content-Type: application/json" -X POST -d '{"path":"/sinatra/ping","image":"treeder/hello-sinatra", "type":"app", "cpath":"/ping"}' http://localhost:8080/test/1/projects/123/apps/myapp/routes
And test it out:
curl -i -X GET http://localhost:8080/sinatra?app=myapp
You'all also get a custom URL like this when in production.
appname.projectid.iron.computer
Building/Testing
Build:
# one time:
glide install
# then every time
./build.sh
Test it, the iron token and project id are for cache.
docker run -e "IRON_TOKEN=GP8cqlKSrcpmqeR8x9WKD4qSAss" -e "IRON_PROJECT_ID=4fd2729368a0197d1102056b" --rm -it --privileged -p 8080:8080 iron/gateway
Push it:
docker push iron/gateway
Get it on a server and point router.iron.computer (on cloudflare) to the machine.
After deploying, running it with:
docker run -e "IRON_TOKEN=GP8cqlKSrcpmqeR8x9WKD4qSAss" -e "IRON_PROJECT_ID=4fd2729368a0197d1102056b" --name irongateway -it --privileged --net=host -p 8080:8080 -d --name irongateway iron/gateway
Description
Languages
Go
97.4%
Shell
1.2%
Ruby
0.5%
Makefile
0.4%
Dockerfile
0.4%
Other
0.1%