50 lines
1.1 KiB
JavaScript
50 lines
1.1 KiB
JavaScript
var express = require("express");
|
|
var logger = require("morgan");
|
|
const http = require("http");
|
|
var helmet = require("helmet");
|
|
var cors = require("cors");
|
|
var dotenv = require("dotenv");
|
|
var needle = require("needle");
|
|
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);
|
|
|
|
//var test = require("./src/test/test");
|
|
|
|
server.listen(3307, () => {console.log("API escuchando en el puerto 3307")});
|
|
|
|
|
|
|