Skip to content

Commit

Permalink
fixes docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
andriibiloussigma authored and strazhnyk committed Nov 22, 2024
1 parent 6d2af75 commit ec25451
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 68 deletions.
11 changes: 5 additions & 6 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use a Node.js base image for building
FROM node:20.14 AS builder
FROM --platform=linux/amd64 node:20.14 AS builder

# Set the working directory
WORKDIR /app
Expand All @@ -21,8 +21,7 @@ ENV REACT_APP_API_URL=$REACT_APP_API_URL
RUN npm run build

# Use Nginx to serve the frontend build
FROM nginx:1.23.2-alpine
COPY --from=builder /app/build /usr/share/nginx/html

# Expose necessary ports
EXPOSE 80
FROM --platform=linux/amd64 nginx:1.23.2-alpine
COPY --from=builder /app/build /var/www/app
COPY ./infra/nginx/conf/ /etc/nginx/conf.d
EXPOSE 80 443
18 changes: 18 additions & 0 deletions client/infra/nginx/conf/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
server {
listen 80;
server_tokens off;

root /var/www/app;

location / {
try_files $uri /index.html;
}

location /api/ {
rewrite ^/api/(.*)$ /$1 break;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-Port $remote_port;
proxy_set_header Host $host;
proxy_pass http://backend:5000;
}
}
2 changes: 1 addition & 1 deletion client/src/components/RequireAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function RequireAuth() {

async function isLoggedIn() {
try {
let response = await axios.get(`${process.env.REACT_APP_API_URL}/api/auth/isLoggedIn`);
let response = await axios.get(`${process.env.REACT_APP_API_URL}/auth/isLoggedIn`);

// Only set states if the component is mounted, otherwise return null.
if (!mountedRef.current) return null;
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function Home({ text, footerText }) {
// stored for making Docusign API calls.
async function getUserInfo() {
try {
let response = await axios.get(`${process.env.REACT_APP_API_URL}/api/auth/login`);
let response = await axios.get(`${process.env.REACT_APP_API_URL}/auth/login`);

// If the user revoked consent after logging in, check to make
// sure they still have consent
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function Login({ text, githubText, btsText }) {
async function handleLogin() {
try {
setSubmitted(true);
let response = await axios.get(`${process.env.REACT_APP_API_URL}/api/auth/login`);
let response = await axios.get(`${process.env.REACT_APP_API_URL}/auth/login`);

// If user has never logged in before, redirect to consent screen
if (response.status === 210) {
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/Passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Passport({ text, formText, btsText }) {

// Send request to server
try {
const response = await sendRequest(`${process.env.REACT_APP_API_URL}/api/passportApplication`, body);
const response = await sendRequest(`${process.env.REACT_APP_API_URL}/passportApplication`, body);
console.log(response.data);

// Redirect to success screen
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/SmallBusinessLoan/SmallBusinessLoan.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function SmallBusinessLoan({ text, formText, btsText, userFlowText }) {

// Send request to server
try {
const response = await sendRequest(`${process.env.REACT_APP_API_URL}/api/loanApplication`, body);
const response = await sendRequest(`${process.env.REACT_APP_API_URL}/loanApplication`, body);

// Received URL for embedded signing, redirect user
if (response.status === 200) {
Expand Down
4 changes: 2 additions & 2 deletions client/src/pages/SmallBusinessLoan/SubmittedLoan.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ function SubmittedLoan({ text }) {
// GETs the loan amount that the user inputted in their loan application,
// and sets the lender name accordingly.
async function getLoanAmount() {
try{
let response = await axios.get(`${process.env.REACT_APP_API_URL}/api/loanApplication/submitted`);
try {
let response = await axios.get(`${process.env.REACT_APP_API_URL}/loanApplication/submitted`);

// Only set states if the component is mounted, otherwise return null.
if (!mountedRef.current) return null;
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/TrafficTicket/SubmittedTrafficTicket.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function SubmittedTrafficTicket({ text }) {
// description of the page accordingly.
async function getUserChoice() {
try {
let response = await axios.get(`${process.env.REACT_APP_API_URL}/api/trafficTicket/submitted`);
let response = await axios.get(`${process.env.REACT_APP_API_URL}/trafficTicket/submitted`);

// Only set states if the component is mounted, otherwise return null.
if (!mountedRef.current) return null;
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/TrafficTicket/TrafficTicket.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function TrafficTicket({ text, formText, btsText, userFlowText }) {

// Send request to server
try {
const response = await sendRequest(`${process.env.REACT_APP_API_URL}/api/trafficTicket`, body);
const response = await sendRequest(`${process.env.REACT_APP_API_URL}/trafficTicket`, body);

// Received URL for embedded signing, redirect user
if (response.status === 200) {
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/TrafficTicket/WitnessStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function WitnessStatement({ text, formText, btsText }) {

// Send request to server
try {
const response = await sendRequest(`${process.env.REACT_APP_API_URL}/api/trafficTicket/sms`, body);
const response = await sendRequest(`${process.env.REACT_APP_API_URL}/trafficTicket/sms`, body);
console.log(response.data);

// Set submitted to true to rerender page.
Expand Down
39 changes: 11 additions & 28 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,23 @@
version: "3.9"

services:
backend:
build:
context: ./server
dockerfile: Dockerfile
container_name: my-backend
ports:
- "5000:5000"
env_file:
- ./server/.env
volumes:
- ./server:/app
- ./server/assets/public:/app/assets/public:ro
networks:
- mynetwork

frontend:
build:
context: ./client
dockerfile: Dockerfile
args:
REACT_APP_API_URL: "http://localhost:5000"
container_name: my-frontend
REACT_APP_API_URL: "http://localhost/api"
container_name: frontend
ports:
- "3000:80"
environment:
- REACT_APP_API_URL=http://localhost:5000
- REACT_APP_NODE_ENV=development
depends_on:
- backend
- 80:80
- 443:443
env_file:
- ./client/.env
networks:
- mynetwork

networks:
mynetwork:
driver: bridge
backend:
build:
context: ./server
dockerfile: Dockerfile
container_name: backend
env_file:
- ./server/.env
2 changes: 1 addition & 1 deletion server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use a Node.js base image
FROM node:20.14
FROM --platform=linux/amd64 node:20.14

# Set the working directory
WORKDIR /app
Expand Down
11 changes: 5 additions & 6 deletions server/controllers/jwtController.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const getUserInfo = async (req) => {
const targetAccountId = process.env.targetAccountId;
const baseUriSuffix = '/restapi';
eSignApi.setOAuthBasePath(oAuthBasePath);

console.log("Seesion Access token", req.session.accessToken)
const results = await eSignApi.getUserInfo(req.session.accessToken);

let accountInfo;
Expand All @@ -74,7 +74,7 @@ const getUserInfo = async (req) => {
if (typeof accountInfo === 'undefined') {
throw new Error(`Target account ${targetAccountId} not found!`);
}

console.log("accountInfo", accountInfo)
req.session.accountId = accountInfo.accountId;
req.session.basePath = accountInfo.baseUri + baseUriSuffix;
} catch (error) {
Expand All @@ -85,15 +85,14 @@ const getUserInfo = async (req) => {
const login = async (req, res, next) => {
try {
req.session.isLoggedIn = true;
await checkToken(req);
await getUserInfo(req);
try { await checkToken(req); await getUserInfo(req); } catch (e) { console.log(e) }
res.status(200).send('Successfully logged in.');
} catch (error) {
if (error.message === 'Consent required') {
const consent_scopes = scopes + '%20impersonation';
const consent_url = `${process.env.DS_OAUTH_SERVER}/oauth/auth?response_type=code&` +
`scope=${consent_scopes}&client_id=${process.env.INTEGRATION_KEY}&` +
`redirect_uri=${process.env.REDIRECT_URI_HOME}`;
`scope=${consent_scopes}&client_id=${process.env.INTEGRATION_KEY}&` +
`redirect_uri=${process.env.REDIRECT_URI_HOME}`;
res.status(210).send(consent_url);
} else {
req.session.isLoggedIn = false;
Expand Down
3 changes: 2 additions & 1 deletion server/controllers/loanController.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const defaultBrandLanguage = 'en';
const createController = async (req, res, next) => {
// Check the access token, which will also update the token
// if it is expired
await checkToken(req);

try { await checkToken(req); } catch (e) { console.log(e) }

// Construct arguments
const { body } = req;
Expand Down
9 changes: 6 additions & 3 deletions server/controllers/trafficController.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ const contestedClerkName = text.contestedClerkName;
* embedded signing session.
*/
const createController = async (req, res, next) => {
console.log("Create controller!")
// Check the access token, which will also update the token
// if it is expired
await checkToken(req);
console.log("REQ", req)

try { await checkToken(req); } catch (e) { console.log(e) }

// Construct arguments
const { body } = req;
Expand Down Expand Up @@ -67,7 +70,7 @@ const createController = async (req, res, next) => {
accountId: req.session.accountId,
envelopeArgs: envelopeArgs,
};

console.log("args", args)
let results = null;

// Send the envelope to signer
Expand Down Expand Up @@ -105,7 +108,7 @@ const createController = async (req, res, next) => {
// Set results
results = { envelopeId: envelopeId, redirectUrl: viewUrl };
} catch (error) {
console.log('Error sending the envelope.');
console.log('Error sending the envelope.', error);
next(error);
}

Expand Down
27 changes: 14 additions & 13 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const trafficRouter = require('./routes/trafficRouter');
const maxSessionAge = 1000 * 60 * 60 * 24 * 1; // One day

const corsOptions = {
origin: 'http://localhost:3000',
credentials: true,
origin: ['http://frontend:3000', 'http://localhost:3000', 'http://localhost:80'],
credentials: true,
};

const app = express()
Expand All @@ -38,12 +38,12 @@ const app = express()
})
);

app.use(cors(corsOptions));
app.use(cors());

app.use((req, res, next) => {
res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin');
next();
});
app.use((req, res, next) => {
res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin');
next();
});


app.get('/', (req, res) => {
Expand All @@ -57,10 +57,10 @@ app.get('/check-session', (req, res) => {
});

// Routing
app.use('/api/auth', authRouter);
app.use('/api/passportApplication', passportRouter);
app.use('/api/loanApplication', loanRouter);
app.use('/api/trafficTicket', trafficRouter);
app.use('/auth', authRouter);
app.use('/passportApplication', passportRouter);
app.use('/loanApplication', loanRouter);
app.use('/trafficTicket', trafficRouter);



Expand Down Expand Up @@ -99,7 +99,7 @@ app.use((err, req, res, next) => {



console.log('process.env.NODE_ENV',process.env.NODE_ENV)
console.log('process.env.NODE_ENV', process.env.NODE_ENV)

// Serve static assets if in production
if (process.env.NODE_ENV === 'production') {
Expand All @@ -111,6 +111,7 @@ if (process.env.NODE_ENV === 'production') {


const port = process.env.PORT_NUMBER;
app.listen(port, () => {
console.log('port on server', port)
app.listen(port, '0.0.0.0', () => {
console.log(`Server started and listening on port ${port}`);
});

0 comments on commit ec25451

Please sign in to comment.