Skip to content

Commit

Permalink
fixes #4:
Browse files Browse the repository at this point in the history
use reverse proxy to make WEBAPI_ENDPOINT configurable
  • Loading branch information
kennethchoe committed Apr 6, 2021
1 parent 9a32d56 commit 6a73140
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 100 deletions.
2 changes: 1 addition & 1 deletion docker-dev-run.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
docker run -d -p:5000:80 --env ASPNETCORE_ENVIRONMENT=Development vertical-slice/web-api
docker run -d -p:8082:80 vertical-slice/vue-app
docker run -d -p:8082:80 --env WEBAPI_ENDPOINT=http://host.docker.internal:5000 vertical-slice/vue-app
2 changes: 1 addition & 1 deletion vue-app/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "cd src && npm install",
"postCreateCommand": "npm install -g @vue/cli && cd src && npm install",

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node"
Expand Down
3 changes: 2 additions & 1 deletion vue-app/src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ RUN npm run build
FROM nginx as production-stage
RUN mkdir /app
COPY --from=build-stage /app/dist /app
COPY nginx.conf /etc/nginx/nginx.conf
COPY nginx.conf /etc/nginx/nginx.conf
COPY nginx.default.conf.template /etc/nginx/templates/default.conf.template
15 changes: 2 additions & 13 deletions vue-app/src/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@ http {
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /app;
index index.html;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}

include /etc/nginx/conf.d/*.conf;
}
16 changes: 16 additions & 0 deletions vue-app/src/nginx.default.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
server {
listen 80;
server_name localhost;
location / {
root /app;
index index.html;
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass ${WEBAPI_ENDPOINT};
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
160 changes: 81 additions & 79 deletions vue-app/src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions vue-app/src/src/components/Weather.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</template>
<script>
import axios from 'axios'
import env from '../env'
export default {
data() {
Expand All @@ -18,7 +17,7 @@ export default {
},
methods: {
refresh() {
axios.get(`${env.serviceUrl}/api/WeatherForecast`)
axios.get('/api/WeatherForecast')
.then(r => {
this.daysInfo = r.data
})
Expand Down
3 changes: 0 additions & 3 deletions vue-app/src/src/env.js

This file was deleted.

10 changes: 10 additions & 0 deletions vue-app/src/vue.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://host.docker.internal:5000',
},
},
},
productionSourceMap: true,
};

0 comments on commit 6a73140

Please sign in to comment.