.
This commit is contained in:
parent
32b75df791
commit
9d2a620302
9
apps/server/.env.development
Normal file
9
apps/server/.env.development
Normal file
@ -0,0 +1,9 @@
|
||||
DB_HOST=localhost
|
||||
DB_USER=rodax
|
||||
DB_PASSWORD=rodax
|
||||
DB_NAME=uecko_erp
|
||||
DB_DIALECT=mariadb
|
||||
DB_PORT=3306
|
||||
|
||||
PORT=3002
|
||||
JWT_SECRET=clave_secreta_para_tokens
|
||||
@ -18,12 +18,26 @@
|
||||
"devDependencies": {
|
||||
"@repo/eslint-config": "workspace:*",
|
||||
"@repo/typescript-config": "workspace:*",
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/node": "^22.10.7",
|
||||
"@types/response-time": "^2.3.8",
|
||||
"@typescript-eslint/eslint-plugin": "^8.22.0",
|
||||
"@typescript-eslint/parser": "^8.22.0",
|
||||
"eslint": "^9.19.0",
|
||||
"nodemon": "^3.1.9",
|
||||
"ts-node-dev": "^2.0.0",
|
||||
"tsx": "^4.19.2",
|
||||
"typescript": "^5.6.3"
|
||||
"typescript": "^5.7.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/express": "^5.0.0",
|
||||
"dotenv": "^16.4.7",
|
||||
"esbuild": "^0.24.0",
|
||||
"express": "^4.21.1"
|
||||
"express": "^4.21.2",
|
||||
"helmet": "^8.0.0",
|
||||
"mariadb": "^3.4.0",
|
||||
"mysql2": "^3.12.0",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"response-time": "^2.3.3",
|
||||
"sequelize": "^6.37.5"
|
||||
}
|
||||
}
|
||||
|
||||
31
apps/server/src/config/app.ts
Normal file
31
apps/server/src/config/app.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import express, { Application } from "express";
|
||||
import responseTime from "response-time";
|
||||
import helmet from "helmet";
|
||||
import dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
export function createApp(): Application {
|
||||
const app = express();
|
||||
|
||||
// secure apps by setting various HTTP headers
|
||||
app.use(helmet());
|
||||
app.disable("x-powered-by");
|
||||
|
||||
// Middlewares
|
||||
app.use(express.json());
|
||||
app.use(express.text());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
// set up the response-time middleware
|
||||
app.use(responseTime());
|
||||
|
||||
app.set("port", process.env.PORT ?? 3002);
|
||||
|
||||
// Rutas (placeholder para bounded contexts)
|
||||
app.get("/", (req, res) => {
|
||||
res.json({ message: "¡Servidor funcionando!" });
|
||||
});
|
||||
|
||||
return app;
|
||||
}
|
||||
26
apps/server/src/config/database.ts
Normal file
26
apps/server/src/config/database.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { Sequelize } from "sequelize";
|
||||
import dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
export const sequelize = new Sequelize(
|
||||
process.env.DB_NAME as string,
|
||||
process.env.DB_USER as string,
|
||||
process.env.DB_PASSWORD as string,
|
||||
{
|
||||
host: process.env.DB_HOST as string,
|
||||
dialect: "mariadb",
|
||||
port: parseInt(process.env.DB_PORT || "3306", 10),
|
||||
logging: false,
|
||||
},
|
||||
);
|
||||
|
||||
export async function connectToDatabase(): Promise<void> {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log("Conexión a MariaDB establecida correctamente.");
|
||||
} catch (error) {
|
||||
console.error("Error al conectar a la base de datos:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,16 @@
|
||||
import express, { Request, Response } from "express";
|
||||
import { createApp } from "./config/app"
|
||||
import { connectToDatabase } from "./config/database";
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
app.get("/", (req: Request, res: Response) => {
|
||||
res.send("Hello World");
|
||||
});
|
||||
(async () => {
|
||||
// Conexión a la base de datos
|
||||
await connectToDatabase();
|
||||
|
||||
app.listen(3000, () => {
|
||||
console.log("Server is running on port 3000");
|
||||
});
|
||||
// Inicializar la aplicación
|
||||
const app = createApp();
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Servidor escuchando en http://localhost:${PORT}`);
|
||||
});
|
||||
})();
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
"volta": {
|
||||
"node": "22.2.0"
|
||||
},
|
||||
"packageManager": "yarn@1.22.22",
|
||||
"packageManager": "pnpm@9.15.4",
|
||||
"workspaces": [
|
||||
"apps/*",
|
||||
"packages/*"
|
||||
|
||||
5905
pnpm-lock.yaml
5905
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user