Skip to content

Commit 3c15fc1

Browse files
committed
fix: adjusts in dockerfile
1 parent 4b32485 commit 3c15fc1

File tree

6 files changed

+21
-23
lines changed

6 files changed

+21
-23
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
* Docker files adjusted
1111
* Fixed in the postman collection the webhookByEvent parameter by webhook_by_events
1212
* Added validations in create instance
13-
* Now it's getting the API URL directly in the request, no longer need the variable in the env file
1413
* Removed link preview endpoint, now it's done automatically from sending conventional text
1514
* Added group membership validation before sending message to groups
1615
* Adjusts in Dockerfile

Docker/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
SERVER_URL='http://localhost:8080' # http://localhost:3333 | http://localhost:3333/api/v1
2+
13
CORS_ORIGIN='*' # Or separate by commas - ex.: 'yourdomain1.com, yourdomain2.com'
24
CORS_METHODS='POST,GET,PUT,DELETE'
35
CORS_CREDENTIALS=true

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ COPY ./package.json .
1313

1414
ENV DOCKER_ENV=true
1515

16+
ENV SERVER_URL='http://localhost:8080'
17+
1618
ENV CORS_ORIGIN=*
1719
ENV CORS_METHODS=POST,GET,PUT,DELETE
1820
ENV CORS_CREDENTIALS=true

src/config/env.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { load } from 'js-yaml';
33
import { join } from 'path';
44
import { isBooleanString } from 'class-validator';
55

6-
export type HttpServer = { TYPE: 'http' | 'https'; PORT: number };
6+
export type HttpServer = { TYPE: 'http' | 'https'; PORT: number; URL: string };
77

88
export type HttpMethods = 'POST' | 'GET' | 'PUT' | 'DELETE';
99
export type Cors = {
@@ -173,6 +173,7 @@ export class ConfigService {
173173
SERVER: {
174174
TYPE: process.env.SERVER_TYPE as 'http' | 'https',
175175
PORT: Number.parseInt(process.env.SERVER_PORT),
176+
URL: process.env.SERVER_URL,
176177
},
177178
CORS: {
178179
ORIGIN: process.env.CORS_ORIGIN.split(','),

src/whatsapp/controllers/instance.controller.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,18 @@ export class InstanceController {
2828

2929
private readonly logger = new Logger(InstanceController.name);
3030

31-
public async createInstance(
32-
{
33-
instanceName,
34-
webhook,
35-
webhook_by_events,
36-
events,
37-
qrcode,
38-
token,
39-
chatwoot_account_id,
40-
chatwoot_token,
41-
chatwoot_url,
42-
chatwoot_sign_msg,
43-
}: InstanceDto,
44-
apiURL: string,
45-
) {
31+
public async createInstance({
32+
instanceName,
33+
webhook,
34+
webhook_by_events,
35+
events,
36+
qrcode,
37+
token,
38+
chatwoot_account_id,
39+
chatwoot_token,
40+
chatwoot_url,
41+
chatwoot_sign_msg,
42+
}: InstanceDto) {
4643
this.logger.verbose('requested createInstance from ' + instanceName + ' instance');
4744

4845
const mode = this.configService.get<Auth>('AUTHENTICATION').INSTANCE.MODE;
@@ -143,7 +140,7 @@ export class InstanceController {
143140
throw new BadRequestException('Invalid "url" property in chatwoot');
144141
}
145142

146-
const urlServer = apiURL;
143+
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
147144

148145
try {
149146
this.chatwootService.create(instance, {
@@ -285,7 +282,7 @@ export class InstanceController {
285282
throw new BadRequestException('Invalid "url" property in chatwoot');
286283
}
287284

288-
const urlServer = apiURL;
285+
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
289286

290287
try {
291288
this.chatwootService.create(instance, {

src/whatsapp/routers/instance.router.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@ export class InstanceRouter extends RouterBroker {
2424
logger.verbose('request query: ');
2525
logger.verbose(req.query);
2626

27-
const apiURL = req.headers.host || req.hostname;
28-
logger.verbose('API URL: ' + apiURL);
29-
3027
const response = await this.dataValidate<InstanceDto>({
3128
request: req,
3229
schema: instanceNameSchema,
3330
ClassRef: InstanceDto,
34-
execute: (instance) => instanceController.createInstance(instance, apiURL),
31+
execute: (instance) => instanceController.createInstance(instance),
3532
});
3633

3734
return res.status(HttpStatus.CREATED).json(response);

0 commit comments

Comments
 (0)