62 lines
1.5 KiB
JavaScript
Executable File
62 lines
1.5 KiB
JavaScript
Executable File
'use strict'
|
|
|
|
|
|
const port = process.env.PORT || 4000; //Puerto
|
|
|
|
const https = require('https'); ///HTTPS
|
|
const fs = require('fs');
|
|
|
|
const OPTIONS_HTTPS = {
|
|
key: fs.readFileSync('./cert/key.pem'),
|
|
cert: fs.readFileSync('./cert/cert.pem')
|
|
};
|
|
|
|
|
|
const express = require('express');
|
|
var cors = require('cors'); //Peticiones cruzadas, por si
|
|
const logger = require('morgan');
|
|
|
|
const app = express();
|
|
|
|
// protege la aplicación de algunas vulnerabilidades web conocidas mediante el establecimiento correcto de cabeceras HTTP.
|
|
const helmet = require('helmet');
|
|
app.use(helmet());
|
|
|
|
//Archivos estaticos
|
|
app.use(express.static('public'));
|
|
|
|
//declaracion
|
|
app.use(logger('dev')); //opciones : tiny, short, dev, common, combined
|
|
app.use(express.urlencoded({ extended: false })); //body generado desde form o postman
|
|
app.use(express.json()); // body con objetos json
|
|
|
|
|
|
var usuarios = require('./routes/usuario');
|
|
app.use('/', usuarios);
|
|
|
|
var datos = require('./routes/datos');
|
|
app.use('/', datos);
|
|
|
|
var compartidos = require('./routes/compartidos');
|
|
app.use('/', compartidos);
|
|
|
|
|
|
|
|
app.get('*', (req, res, next) => {
|
|
res.writeHead(301,
|
|
{Location: `https://192.168.10.2:${port}/home.html`}
|
|
);
|
|
res.end();
|
|
});
|
|
|
|
//HTTPS
|
|
https.createServer(OPTIONS_HTTPS, app).listen(port, '0.0.0.0', () => {
|
|
console.log(`API REST ejecutándose en https://localhost:${port}/`);
|
|
})
|
|
|
|
|
|
// Iniciamos la aplicación
|
|
/*app.listen(port, 'localhost', () => {
|
|
console.log(`API REST ejecutándose en http://localhost:${port}/`);
|
|
});*/
|