DiscofyAPI/index.js

45 lines
1.0 KiB
JavaScript
Raw Normal View History

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");
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);
server.listen(3307, () => {console.log("API escuchando en el puerto 3307")});