Skip to content

Commit

Permalink
feat: add v2 route for separate backend service config (#1285)
Browse files Browse the repository at this point in the history
Co-authored-by: Leland Garofalo <[email protected]>
  • Loading branch information
lgarofalo and Leland Garofalo authored Aug 15, 2023
1 parent 0ad60d0 commit 64da16a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docker/tiller/templates/askdarcel-web.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ server {
proxy_redirect off;
}

location ~ ^/api/v2/(.*)$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;

# See https://forum.nginx.org/read.php?2,215830,215832#msg-215832
# nginx only resolves DNS for statically-configured domain names
# once on startup. Since the API is behind an ELB whose IPs may
# change, we must configure nginx to resolve DNS dynamically.
# To do this, we configure a DNS resolver here and use a variable
# rather than a literal URL when configuring the proxy below.
resolver <%= open('/etc/resolv.conf').read.match(/nameserver (.*)/)[1] rescue '8.8.8.8' %>;
resolver_timeout 5s;

set api_go_url <%= env_api_go_url.chomp '/' %>;
proxy_pass $api_go_url/$1$is_args$args;
proxy_redirect off;
}

location ~ ^/api/(.*)$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand Down
4 changes: 4 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ module.exports = {
"/api-docs": {
target: process.env.API_URL || "http://localhost:3000",
},
"/api/v2/": {
target: process.env.API_GO_URL || "http://localhost:3000",
pathRewrite: { "^/api/v2/": "" },
},
"/api/": {
target: process.env.API_URL || "http://localhost:3000",
pathRewrite: { "^/api/": "" },
Expand Down

0 comments on commit 64da16a

Please sign in to comment.