Skip to content

Commit

Permalink
fix: fix coupon service env (#22)
Browse files Browse the repository at this point in the history
* fix: use the same env var for host references for every service

* feat: add docker compose file

* feat: use npm ci to install node deps
  • Loading branch information
rauno56 authored Jun 20, 2024
1 parent 352a908 commit e804b15
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 511 deletions.
2 changes: 1 addition & 1 deletion coupon/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:18.3.0-alpine3.14
COPY . /app
WORKDIR /app
RUN npm install
RUN npm ci
USER 15000
CMD ["node", "app.js"]
17 changes: 15 additions & 2 deletions coupon/app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
const assert = require('assert/strict');
const util = require('util');

const express = require('express');

const PORT = parseInt(process.env.PORT || '8080');
const app = express();
const axios = require('axios');

const {
MEMBERSHIP_SERVICE_HOST,
} = process.env;

assert.equal(
typeof MEMBERSHIP_SERVICE_HOST,
'string',
`Expexted 'MEMBERSHIP_SERVICE_HOST' to be set. Got: ${util.format(MEMBERSHIP_SERVICE_HOST)}`
);

function getRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
Expand All @@ -16,7 +29,7 @@ app.get('/coupons', (req, res) => {
console.log('Coupon request received!');

// Fetch from membership api
axios.get(`http://${process.env.MEMBERSHIP_SERVICE_URL}/isMember`)
axios.get(`http://${MEMBERSHIP_SERVICE_HOST}/isMember`)
.then(function (response) {
console.log('Got response from membership service!', response.data);
res.json({
Expand All @@ -33,7 +46,7 @@ app.post('/apply-coupon', (req, res) => {
console.log('Applying coupon!');

// Fetch from membership api
axios.get(`http://${process.env.MEMBERSHIP_SERVICE_URL}/isMember`)
axios.get(`http://${MEMBERSHIP_SERVICE_HOST}/isMember`)
.then(function (response) {
console.log('Got response from membership service!', response.data);
res.json({
Expand Down
Loading

0 comments on commit e804b15

Please sign in to comment.