2021-03-25 17:23:36 +01:00
|
|
|
var express = require("express");
|
|
|
|
var logger = require("morgan");
|
|
|
|
const http = require("http");
|
|
|
|
var helmet = require("helmet");
|
|
|
|
var cors = require("cors");
|
|
|
|
var dotenv = require("dotenv");
|
2021-05-20 17:54:33 +02:00
|
|
|
var needle = require("needle");
|
2021-03-25 17:23:36 +01:00
|
|
|
const mariadb = require("mariadb");
|
|
|
|
|
|
|
|
dotenv.config();
|
|
|
|
|
|
|
|
var app = express();
|
|
|
|
app.use(express.json());
|
|
|
|
app.use(express.urlencoded({extended: false}));
|
|
|
|
var corsOptions = {
|
|
|
|
origin: 'http://localhost:8100',
|
|
|
|
optionsSuccessStatus: 200
|
|
|
|
}
|
|
|
|
app.use(cors(corsOptions));
|
|
|
|
app.use(helmet());
|
|
|
|
|
|
|
|
//Router de consultas por URL
|
|
|
|
var routerConsultas = require('./src/routes/rutas');
|
|
|
|
|
|
|
|
//Ruta de las consultas
|
|
|
|
app.use('/api/consultas', routerConsultas);
|
|
|
|
app.use(logger('dev'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mariadb.createConnection({
|
|
|
|
host: process.env.DB_HOST,
|
|
|
|
user: process.env.DB_USER,
|
|
|
|
password: process.env.DB_PWD,
|
|
|
|
database: process.env.DB_NAME
|
|
|
|
}).then (_=> {
|
|
|
|
console.log("Conexión a la BD correcta. ")
|
|
|
|
}).catch( err => {
|
|
|
|
console.log("Error conectando a la BD: "+err);
|
|
|
|
})
|
|
|
|
|
|
|
|
const server = http.createServer(app);
|
|
|
|
|
2021-05-22 16:12:25 +02:00
|
|
|
//var test = require("./src/test/test");
|
2021-05-20 17:54:33 +02:00
|
|
|
|
2021-03-25 17:23:36 +01:00
|
|
|
server.listen(3307, () => {console.log("API escuchando en el puerto 3307")});
|
|
|
|
|
2021-05-20 17:54:33 +02:00
|
|
|
|
|
|
|
|