fix: adjusts in dockerfile

This commit is contained in:
Davidson Gomes 2023-07-16 19:05:17 -03:00
parent 4b32485e3c
commit 3c15fc1b0d
6 changed files with 21 additions and 23 deletions

View File

@ -10,7 +10,6 @@
* Docker files adjusted * Docker files adjusted
* Fixed in the postman collection the webhookByEvent parameter by webhook_by_events * Fixed in the postman collection the webhookByEvent parameter by webhook_by_events
* Added validations in create instance * Added validations in create instance
* Now it's getting the API URL directly in the request, no longer need the variable in the env file
* Removed link preview endpoint, now it's done automatically from sending conventional text * Removed link preview endpoint, now it's done automatically from sending conventional text
* Added group membership validation before sending message to groups * Added group membership validation before sending message to groups
* Adjusts in Dockerfile * Adjusts in Dockerfile

View File

@ -1,3 +1,5 @@
SERVER_URL='http://localhost:8080' # http://localhost:3333 | http://localhost:3333/api/v1
CORS_ORIGIN='*' # Or separate by commas - ex.: 'yourdomain1.com, yourdomain2.com' CORS_ORIGIN='*' # Or separate by commas - ex.: 'yourdomain1.com, yourdomain2.com'
CORS_METHODS='POST,GET,PUT,DELETE' CORS_METHODS='POST,GET,PUT,DELETE'
CORS_CREDENTIALS=true CORS_CREDENTIALS=true

View File

@ -13,6 +13,8 @@ COPY ./package.json .
ENV DOCKER_ENV=true ENV DOCKER_ENV=true
ENV SERVER_URL='http://localhost:8080'
ENV CORS_ORIGIN=* ENV CORS_ORIGIN=*
ENV CORS_METHODS=POST,GET,PUT,DELETE ENV CORS_METHODS=POST,GET,PUT,DELETE
ENV CORS_CREDENTIALS=true ENV CORS_CREDENTIALS=true

View File

@ -3,7 +3,7 @@ import { load } from 'js-yaml';
import { join } from 'path'; import { join } from 'path';
import { isBooleanString } from 'class-validator'; import { isBooleanString } from 'class-validator';
export type HttpServer = { TYPE: 'http' | 'https'; PORT: number }; export type HttpServer = { TYPE: 'http' | 'https'; PORT: number; URL: string };
export type HttpMethods = 'POST' | 'GET' | 'PUT' | 'DELETE'; export type HttpMethods = 'POST' | 'GET' | 'PUT' | 'DELETE';
export type Cors = { export type Cors = {
@ -173,6 +173,7 @@ export class ConfigService {
SERVER: { SERVER: {
TYPE: process.env.SERVER_TYPE as 'http' | 'https', TYPE: process.env.SERVER_TYPE as 'http' | 'https',
PORT: Number.parseInt(process.env.SERVER_PORT), PORT: Number.parseInt(process.env.SERVER_PORT),
URL: process.env.SERVER_URL,
}, },
CORS: { CORS: {
ORIGIN: process.env.CORS_ORIGIN.split(','), ORIGIN: process.env.CORS_ORIGIN.split(','),

View File

@ -28,21 +28,18 @@ export class InstanceController {
private readonly logger = new Logger(InstanceController.name); private readonly logger = new Logger(InstanceController.name);
public async createInstance( public async createInstance({
{ instanceName,
instanceName, webhook,
webhook, webhook_by_events,
webhook_by_events, events,
events, qrcode,
qrcode, token,
token, chatwoot_account_id,
chatwoot_account_id, chatwoot_token,
chatwoot_token, chatwoot_url,
chatwoot_url, chatwoot_sign_msg,
chatwoot_sign_msg, }: InstanceDto) {
}: InstanceDto,
apiURL: string,
) {
this.logger.verbose('requested createInstance from ' + instanceName + ' instance'); this.logger.verbose('requested createInstance from ' + instanceName + ' instance');
const mode = this.configService.get<Auth>('AUTHENTICATION').INSTANCE.MODE; const mode = this.configService.get<Auth>('AUTHENTICATION').INSTANCE.MODE;
@ -143,7 +140,7 @@ export class InstanceController {
throw new BadRequestException('Invalid "url" property in chatwoot'); throw new BadRequestException('Invalid "url" property in chatwoot');
} }
const urlServer = apiURL; const urlServer = this.configService.get<HttpServer>('SERVER').URL;
try { try {
this.chatwootService.create(instance, { this.chatwootService.create(instance, {
@ -285,7 +282,7 @@ export class InstanceController {
throw new BadRequestException('Invalid "url" property in chatwoot'); throw new BadRequestException('Invalid "url" property in chatwoot');
} }
const urlServer = apiURL; const urlServer = this.configService.get<HttpServer>('SERVER').URL;
try { try {
this.chatwootService.create(instance, { this.chatwootService.create(instance, {

View File

@ -24,14 +24,11 @@ export class InstanceRouter extends RouterBroker {
logger.verbose('request query: '); logger.verbose('request query: ');
logger.verbose(req.query); logger.verbose(req.query);
const apiURL = req.headers.host || req.hostname;
logger.verbose('API URL: ' + apiURL);
const response = await this.dataValidate<InstanceDto>({ const response = await this.dataValidate<InstanceDto>({
request: req, request: req,
schema: instanceNameSchema, schema: instanceNameSchema,
ClassRef: InstanceDto, ClassRef: InstanceDto,
execute: (instance) => instanceController.createInstance(instance, apiURL), execute: (instance) => instanceController.createInstance(instance),
}); });
return res.status(HttpStatus.CREATED).json(response); return res.status(HttpStatus.CREATED).json(response);