Update for production backup

This commit is contained in:
2026-07-15 19:10:51 -06:00
commit 51df64ef1f
29 changed files with 10631 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
# compiled output
/dist
/node_modules
/build
# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# temp directory
.temp
.tmp
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
+1
View File
@@ -0,0 +1 @@
23
+4
View File
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
+76
View File
@@ -0,0 +1,76 @@
# TessCorp API Backend
Backend API para el formulario de contacto del portfolio de TessCorp, construido con NestJS.
## Funcionalidad
- Endpoint POST `/contact` para enviar correos de contacto
- Validación de datos con class-validator
- Integración con Nodemailer para envío de correos
- Configuración CORS para permitir peticiones desde el frontend
## Configuración
1. Copiar el archivo de entorno:
```bash
cp .env.example .env
```
2. Configurar las variables de entorno en `.env`:
```
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USER=your-email@gmail.com
EMAIL_PASS=your-app-password
EMAIL_FROM=your-email@gmail.com
PORT=3000
NODE_ENV=development
```
## Instalación
```bash
$ npm install
```
## Ejecución
```bash
# desarrollo
$ npm run start:dev
# producción
$ npm run start:prod
```
## API Endpoint
### POST /contact
Envía un correo electrónico con los datos del formulario de contacto.
**Body:**
```json
{
"name": "Juan Pérez",
"email": "juan@example.com",
"message": "Mensaje de prueba",
"subject": "Asunto opcional"
}
```
**Response:**
```json
{
"success": true,
"message": "Email sent successfully"
}
```
## Tecnologías
- NestJS
- TypeScript
- Nodemailer
- class-validator
- class-transformer
+35
View File
@@ -0,0 +1,35 @@
// @ts-check
import eslint from '@eslint/js';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import globals from 'globals';
import tseslint from 'typescript-eslint';
export default tseslint.config(
{
ignores: ['eslint.config.mjs'],
},
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
eslintPluginPrettierRecommended,
{
languageOptions: {
globals: {
...globals.node,
...globals.jest,
},
sourceType: 'commonjs',
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
"prettier/prettier": ["error", { endOfLine: "auto" }],
},
},
);
+28
View File
@@ -0,0 +1,28 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Domain Default page</title>
<meta name="copyright" content="Copyright 1999-2025. WebPros International GmbH. All rights reserved.">
<script src="https://assets.plesk.com/static/default-website-content/public/default-website-index.js"></script>
</head>
<body>
<h2>What is Plesk</h2>
<p>
Plesk is a <a href="https://www.plesk.com">hosting panel</a> with simple and secure web server, website and web apps management tools. It is specially designed to help web professionals manage web, DNS, mail and other services through a comprehensive and user-friendly GUI. Plesk is about intelligently managing servers, apps, websites and hosting businesses, on both traditional and cloud hosting.
</p>
<p>
<a href="https://docs.plesk.com/try-plesk-now/">Try Plesk Now!</a>
</p>
<ul>
<li><a href="https://docs.plesk.com/en-US/obsidian/">Plesk Guides</a></li>
<li><a href="https://support.plesk.com/hc/en-us">Knowledge Base</a></li>
<li><a href="https://talk.plesk.com/">Forum</a></li>
<li><a href="https://www.plesk.com/blog/">Blog</a></li>
<li><a href="https://www.youtube.com/channel/UCeU-_6YHGQFcVSHLbEXLNlA/playlists">Video Guides</a></li>
<li><a href="https://www.facebook.com/Plesk">Facebook</a></li>
</ul>
<p>Do you host WordPress sites outside of Plesk? Try <a href="https://wpguardian.io/">WP Guardian</a> - it provides complete visibility into the health of your WordPress websites in one place and keeps them protected with flexible updates management</p>
</body>
</html>
+1
View File
@@ -0,0 +1 @@
require('./dist/main.js');
+8
View File
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
}
+9976
View File
File diff suppressed because it is too large Load Diff
+75
View File
@@ -0,0 +1,75 @@
{
"name": "api.tesscorp.com.mx",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/common": "^11.0.1",
"@nestjs/config": "^4.0.3",
"@nestjs/core": "^11.0.1",
"@nestjs/platform-express": "^11.0.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.3",
"nodemailer": "^8.0.0",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1"
},
"devDependencies": {
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.18.0",
"@nestjs/cli": "^11.0.0",
"@nestjs/schematics": "^11.0.0",
"@nestjs/testing": "^11.0.1",
"@types/express": "^5.0.0",
"@types/jest": "^30.0.0",
"@types/node": "^22.10.7",
"@types/supertest": "^6.0.2",
"eslint": "^9.18.0",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-prettier": "^5.2.2",
"globals": "^16.0.0",
"jest": "^30.0.0",
"prettier": "^3.4.2",
"source-map-support": "^0.5.21",
"supertest": "^7.0.0",
"ts-jest": "^29.2.5",
"ts-loader": "^9.5.2",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.7.3",
"typescript-eslint": "^8.20.0"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
+1
View File
@@ -0,0 +1 @@
/var/www/vhosts/system/api.tesscorp.com.mx/etc/php.ini
+1
View File
@@ -0,0 +1 @@
8.3
+7
View File
@@ -0,0 +1,7 @@
<!doctype html>
<html>
<body>
<h1>Hello World!</h1>
<p>API running.</p>
</body>
</html>
+22
View File
@@ -0,0 +1,22 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
describe('AppController', () => {
let appController: AppController;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
appController = app.get<AppController>(AppController);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});
+15
View File
@@ -0,0 +1,15 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
@Controller()
export class AppController {
@Get()
root() {
return { status: 'ok', service: 'api.tesscorp.com.mx' };
}
@Get('health')
health() {
return { ok: true };
}
}
+17
View File
@@ -0,0 +1,17 @@
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ContactModule } from './contact/contact.module';
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
}),
ContactModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
+8
View File
@@ -0,0 +1,8 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getHello(): string {
return 'Hello Worldalk;sdjflkasjkdf!';
}
}
+18
View File
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ContactController } from './contact.controller';
describe('ContactController', () => {
let controller: ContactController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [ContactController],
}).compile();
controller = module.get<ContactController>(ContactController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});
+19
View File
@@ -0,0 +1,19 @@
import { Controller, Post, Body, HttpCode, HttpStatus } from '@nestjs/common';
import { ContactService } from './contact.service';
import { CreateContactDto } from './dto/create-contact.dto';
@Controller('api/contact')
export class ContactController {
constructor(private readonly contactService: ContactService) {}
@Post()
@HttpCode(HttpStatus.OK)
async sendContact(@Body() dto: CreateContactDto) {
return this.contactService.sendContactEmail({
name: dto.nombre,
email: dto.email,
message: dto.mensaje,
subject: dto.subject, // opcional, solo si existe en DTO
});
}
}
+9
View File
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { ContactController } from './contact.controller';
import { ContactService } from './contact.service';
@Module({
controllers: [ContactController],
providers: [ContactService]
})
export class ContactModule {}
+18
View File
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ContactService } from './contact.service';
describe('ContactService', () => {
let service: ContactService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [ContactService],
}).compile();
service = module.get<ContactService>(ContactService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
+125
View File
@@ -0,0 +1,125 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import * as nodemailer from 'nodemailer';
@Injectable()
export class ContactService {
private transporter: nodemailer.Transporter;
constructor(private configService: ConfigService) {
// Leer variables (TODAS vienen como string desde .env)
const host = this.configService.get<string>('EMAIL_HOST');
const port = Number(this.configService.get<string>('EMAIL_PORT'));
const user = this.configService.get<string>('EMAIL_USER');
const pass = this.configService.get<string>('EMAIL_PASS');
// Guardas duras (mejor fallar al arrancar que en runtime)
if (!host || !port || !user || !pass) {
throw new Error(
`SMTP config missing or invalid:
host=${host}
port=${port}
user=${user}
pass=${pass ? '***' : 'EMPTY'}`
);
}
this.transporter = nodemailer.createTransport({
host,
port,
secure: port === 465, // 465 = SSL directo
requireTLS: port === 587, // 587 = STARTTLS
auth: {
user,
pass,
},
});
}
async sendContactEmail(contactData: {
name: string;
email: string;
message: string;
subject?: string;
}) {
const { name, email, message, subject } = contactData;
const to = this.configService.get<string>('EMAIL_USER');
const mailOptions: nodemailer.SendMailOptions = {
from: `"TESS Web" <${to}>`,
to,
replyTo: email,
subject: `🚀 Nuevo contacto en TESS — ${name}`,
html: `
<div style="font-family: Arial, sans-serif; background:#f6f8fb; padding:24px;">
<div style="max-width:640px; margin:0 auto; background:#ffffff; border-radius:10px; overflow:hidden; border:1px solid #e8eef5;">
<!-- Header -->
<div style="background:linear-gradient(90deg,#35ffd9,#0cc0df); padding:18px 24px; color:#061018;">
<div style="font-size:12px; letter-spacing:0.6px; text-transform:uppercase; opacity:0.85;">
TESS · Tecnologías que impulsan tu éxito.
</div>
<div style="font-size:20px; font-weight:700; margin-top:6px;">
Nuevo mensaje desde tesscorp.com.mx
</div>
</div>
<!-- Body -->
<div style="padding:22px 24px;">
<div style="background:#f0fbff; border:1px solid #d7f3fb; padding:12px 14px; border-radius:8px; margin-bottom:16px;">
<div style="font-size:13px; color:#055a6a;">
📩 <strong>Nuevo lead</strong> · Responde directamente a este correo para contestar al cliente.
</div>
</div>
<table style="width:100%; border-collapse:collapse; margin-bottom:18px;">
<tr>
<td style="padding:8px 0; width:110px; color:#667; font-size:13px;"><strong>Nombre</strong></td>
<td style="padding:8px 0; color:#111; font-size:14px;">${name}</td>
</tr>
<tr>
<td style="padding:8px 0; color:#667; font-size:13px;"><strong>Email</strong></td>
<td style="padding:8px 0; font-size:14px;">
<a href="mailto:${email}" style="color:#0b7ea1; text-decoration:none;">${email}</a>
</td>
</tr>
</table>
<div style="margin:10px 0 6px; font-weight:700; color:#111;">Mensaje</div>
<div style="background:#fafafa; border:1px solid #eee; padding:14px; border-radius:8px; color:#111; white-space:pre-line; line-height:1.5;">
${message}
</div>
<div style="margin-top:18px;">
<a href="mailto:${email}"
style="display:inline-block; background:#0cc0df; color:#061018; padding:10px 14px; border-radius:8px; font-weight:700; text-decoration:none;">
Responder a ${name}
</a>
</div>
</div>
<div style="padding:12px 24px; background:#f6f8fb; color:#667; font-size:12px;">
Origen: <strong>https://tesscorp.com.mx</strong> · Formulario de contacto
</div>
</div>
</div>
`,
};
try {
await this.transporter.sendMail(mailOptions);
return { success: true, message: 'Email sent successfully' };
} catch (error: any) {
// Log real para servidor
console.error('Error sending contact email:', error);
// Respuesta limpia para frontend
return {
success: false,
message: error?.message || 'Error sending email',
};
}
}
}
+18
View File
@@ -0,0 +1,18 @@
import { IsEmail, IsNotEmpty, IsString, IsOptional } from 'class-validator';
export class CreateContactDto {
@IsString()
@IsNotEmpty()
nombre: string;
@IsEmail()
email: string;
@IsString()
@IsNotEmpty()
mensaje: string;
@IsOptional()
@IsString()
subject?: string;
}
+30
View File
@@ -0,0 +1,30 @@
import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors({
origin: [
'https://tesscorp.com.mx',
'http://localhost:5173',
'http://127.0.0.1:5173',
],
credentials: false, // <-- pon true SOLO si usas cookies + fetch credentials: 'include'
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization'],
});
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
forbidNonWhitelisted: true,
transform: true,
}),
);
await app.listen(process.env.PORT ?? 3000);
console.log(`Application is running on: ${await app.getUrl()}`);
}
bootstrap();
+25
View File
@@ -0,0 +1,25 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import request from 'supertest';
import { App } from 'supertest/types';
import { AppModule } from './../src/app.module';
describe('AppController (e2e)', () => {
let app: INestApplication<App>;
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
});
it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
});
});
+9
View File
@@ -0,0 +1,9 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}
View File
+4
View File
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}
+25
View File
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "nodenext",
"moduleResolution": "nodenext",
"resolvePackageJsonExports": true,
"esModuleInterop": true,
"isolatedModules": true,
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2023",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"noImplicitAny": false,
"strictBindCallApply": false,
"noFallthroughCasesInSwitch": false
}
}