Skip to content

Commit a21fe07

Browse files
committed
Modification to make the project run on kubernetes and without SSL
1 parent 0056080 commit a21fe07

3 files changed

Lines changed: 56 additions & 53 deletions

File tree

backend/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSI
1010
RUN apt-get update \
1111
&& apt-get install -y wget gnupg \
1212
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
13-
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
13+
&& echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list \
1414
&& apt-get update \
1515
&& apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \
1616
--no-install-recommends \
@@ -31,10 +31,13 @@ RUN npm run build
3131
ENV NODE_ENV=production
3232
ENV PORT=3000
3333
ENV CHROME_BIN=google-chrome-stable
34+
ENV CHROME_ARGS='--no-sandbox --disable-setuid-sandbox'
3435

3536
EXPOSE 3000
3637

3738
ENTRYPOINT ["dumb-init", "--"]
3839
CMD dockerize -wait tcp://${DB_HOST}:3306 \
3940
&& npx sequelize db:migrate \
40-
&& node dist/server.js
41+
# Executar na primeira utilização da App
42+
# && npx sequelize db:seed:all \
43+
&& node dist/server.js

backend/src/services/WbotServices/wbotMessageListener.ts

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,6 @@ const verifyQuotedMessage = async (
6363
return quotedMsg;
6464
};
6565

66-
67-
// generate random id string for file names, function got from: https://stackoverflow.com/a/1349426/1851801
68-
function makeRandomId(length: number) {
69-
let result = '';
70-
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
71-
const charactersLength = characters.length;
72-
let counter = 0;
73-
while (counter < length) {
74-
result += characters.charAt(Math.floor(Math.random() * charactersLength));
75-
counter += 1;
76-
}
77-
return result;
78-
}
79-
8066
const verifyMediaMessage = async (
8167
msg: WbotMessage,
8268
ticket: Ticket,
@@ -90,13 +76,9 @@ const verifyMediaMessage = async (
9076
throw new Error("ERR_WAPP_DOWNLOAD_MEDIA");
9177
}
9278

93-
let randomId = makeRandomId(5);
94-
9579
if (!media.filename) {
9680
const ext = media.mimetype.split("/")[1].split(";")[0];
97-
media.filename = `${randomId}-${new Date().getTime()}.${ext}`;
98-
} else {
99-
media.filename = media.filename.split('.').slice(0,-1).join('.')+'.'+randomId+'.'+media.filename.split('.').slice(-1);
81+
media.filename = `${new Date().getTime()}.${ext}`;
10082
}
10183

10284
try {
@@ -128,38 +110,44 @@ const verifyMediaMessage = async (
128110
return newMessage;
129111
};
130112

113+
131114
const verifyMessage = async (
132115
msg: WbotMessage,
133116
ticket: Ticket,
134117
contact: Contact
135-
) => {
136-
137-
if (msg.type === 'location')
138-
msg = prepareLocation(msg);
118+
) => {
119+
if (msg.type === "location") msg = prepareLocation(msg);
120+
139121

140122
const quotedMsg = await verifyQuotedMessage(msg);
141123
const messageData = {
142-
id: msg.id.id,
143-
ticketId: ticket.id,
144-
contactId: msg.fromMe ? undefined : contact.id,
145-
body: msg.body,
146-
fromMe: msg.fromMe,
147-
mediaType: msg.type,
148-
read: msg.fromMe,
149-
quotedMsgId: quotedMsg?.id
124+
id: msg.id.id,
125+
ticketId: ticket.id,
126+
contactId: msg.fromMe ? undefined : contact.id,
127+
body: msg.body,
128+
fromMe: msg.fromMe,
129+
mediaType: msg.type,
130+
read: msg.fromMe,
131+
quotedMsgId: quotedMsg?.id
150132
};
151133

152-
await ticket.update({ lastMessage: msg.type === "location" ? msg.location.description ? "Localization - " + msg.location.description.split('\\n')[0] : "Localization" : msg.body });
134+
await ticket.update({
135+
lastMessage:
136+
msg.type === "location"
137+
? msg.location.options || "Localization"
138+
: msg.body
139+
});
153140

154141
await CreateMessageService({ messageData });
155142
};
156143

157144
const prepareLocation = (msg: WbotMessage): WbotMessage => {
158-
let gmapsUrl = "https://maps.google.com/maps?q=" + msg.location.latitude + "%2C" + msg.location.longitude + "&z=17&hl=pt-BR";
159145

160-
msg.body = "data:image/png;base64," + msg.body + "|" + gmapsUrl;
161146

162-
msg.body += "|" + (msg.location.description ? msg.location.description : (msg.location.latitude + ", " + msg.location.longitude))
147+
const gmapsUrl = "https://maps.google.com/maps?q=${msg.location.latitude}%2C${msg.location.longitude}&z=17";
148+
msg.body = 'data:image/png;base64,${msg.body}|${gmapsUrl}';
149+
150+
msg.body += "|" + (msg.location.options ? msg.location.options : (msg.location.latitude + ", " + msg.location.longitude))
163151

164152
return msg;
165153
};

frontend/Dockerfile

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
FROM node:14-alpine as build-deps
22
WORKDIR /usr/src/app
3-
COPY package*.json ./
3+
4+
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 /usr/local/bin/dumb-init
5+
RUN chmod +x /usr/local/bin/dumb-init
6+
7+
# COPY package*.json ./
8+
# RUN npm install
9+
# COPY .env* ./
10+
# COPY src/ ./src/
11+
# COPY public/ ./public/
12+
# RUN npm run build
13+
14+
COPY . ./
415
RUN npm install
5-
COPY .env* ./
6-
COPY src/ ./src/
7-
COPY public/ ./public/
16+
RUN echo "REACT_APP_BACKEND_URL=http://whaticket-backend.stg.hucloud.com.br/" > .env
817
RUN npm run build
918

10-
FROM nginx:alpine
11-
RUN apk add --no-cache jq openssl
19+
ENTRYPOINT ["dumb-init", "--"]
20+
CMD node server.js
21+
22+
# FROM nginx:alpine
23+
# RUN apk add --no-cache jq openssl
1224

13-
ENV DOCKERIZE_VERSION v0.6.1
14-
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
15-
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
16-
&& rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz
25+
# ENV DOCKERIZE_VERSION v0.6.1
26+
# RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
27+
# && tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
28+
# && rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz
1729

18-
ENV PUBLIC_HTML=/var/www/public/
30+
# ENV PUBLIC_HTML=/var/www/public/
1931

20-
COPY .docker/nginx /etc/nginx/
21-
COPY --from=build-deps /usr/src/app/build ${PUBLIC_HTML}
22-
EXPOSE 80
32+
# COPY .docker/nginx /etc/nginx/
33+
# COPY --from=build-deps /usr/src/app/build ${PUBLIC_HTML}
34+
# EXPOSE 80
2335

24-
COPY .docker/add-env-vars.sh /docker-entrypoint.d/01-add-env-vars.sh
25-
RUN chmod +x /docker-entrypoint.d/01-add-env-vars.sh
36+
# COPY .docker/add-env-vars.sh /docker-entrypoint.d/01-add-env-vars.sh
37+
# RUN chmod +x /docker-entrypoint.d/01-add-env-vars.sh

0 commit comments

Comments
 (0)