Skip to content

Commit

Permalink
Network simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
algarfer committed Apr 3, 2024
1 parent 27d4ff1 commit ca1b77d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 47 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,6 @@ jobs:
- name: Check out the repo
uses: actions/checkout@v4

- name: Create SSL certificates
run: |
echo "${{ secrets.DEPLOY_SSL_CERT }}" > gatewayservice/certificate.crt
echo "${{ secrets.DEPLOY_SSL_CA_BUNDLE }}" > gatewayservice/ca_bundle.crt
echo "${{ secrets.DEPLOY_SSL_KEY }}" > gatewayservice/private.key
shell: bash

- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ services:
- jordi-think
- ranking
ports:
- "7999:7999"
- "8000:8000"
networks:
- mynetwork
Expand Down
1 change: 0 additions & 1 deletion gatewayservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ RUN npm install
# Copy the app source code to the working directory
COPY . .

EXPOSE 7999
EXPOSE 8000

# Define the command to run your app
Expand Down
25 changes: 4 additions & 21 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,8 @@ const cors = require('cors');
const promBundle = require('express-prom-bundle');
const axios = require('axios');

const https = require('https');
const fs = require('fs');

const app = express();
const httpPort = 8000;
const httpsPort = 7999;

const sslServerKey = fs.readFileSync('./private.key');
const sslServerCert = fs.readFileSync('./certificate.crt');
const sslCaBundle = fs.readFileSync('./ca_bundle.crt');

const httpsServer = https.createServer({
key: sslServerKey,
cert: sslServerCert,
ca: sslCaBundle
}, app)
const port = 8000;

app.use(cors());
app.use(express.json());
Expand Down Expand Up @@ -46,10 +32,7 @@ require("./routes/authRoutes")(app, axios, errorHandler)
require("./routes/historyRoutes")(app, axios, errorHandler, authTokenMiddleware)

// Start the gateway service
const server = app.listen(httpPort, () =>
console.log(`Gateway Service (HTTP) listening at port ${httpPort}`));

httpsServer.listen(httpsPort, () =>
console.log(`Gateway Service (HTTPS) listening at port ${httpsPort}`));
const server = app.listen(port, () =>
console.log(`Gateway Service listening at port ${port}`));

module.exports = server
module.exports = server
21 changes: 4 additions & 17 deletions proxy/default.conf
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
server {
listen 80;
listen [::]:80;
server_name _;

location / {
proxy_pass http://webapp:3000;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /api/ {
proxy_pass http://gatewayservice:8000/;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

server {
listen 443 ssl;

listen [::]:80;
listen [::]:443 ssl;

server_name _;

# SSL configuration
ssl_certificate /etc/nginx/ssl/certificate.crt;
ssl_certificate_key /etc/nginx/ssl/private.key;
ssl_trusted_certificate /etc/nginx/ssl/ca_bundle.crt;
Expand All @@ -30,7 +17,7 @@ server {
}

location /api/ {
proxy_pass https://gatewayservice:7999/;
proxy_pass http://gatewayservice:8000/;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

0 comments on commit ca1b77d

Please sign in to comment.