Commit 303a6a09 authored by Esteban Choque's avatar Esteban Choque

Initial commit

parents
Pipeline #1359 failed with stages
node_modules/
package-lock.json
Instalacion de nodejs
---------------------
#### Instalación de dependencias
Actualizar paquetes
```
sudo apt update
sudo apt-get install build-essential libssl-dev
```
Descarga de paquetes
```
curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh -o install_nvm.sh
```
Verificación
```
nano install_nvm.sh
```
Ejecutar script
```
bash install_nvm.sh
source ~/.profile
```
Mostrar versiones
```
nvm ls-remote
```
Instalar npm
```
nvm install v8.12.0
```
Usar version de nvm
```
nvm use 8.12.0
```
#### Instalacion del backend
Descargar proyecto
```
git clone git@gitlab.geo.gob.bo:cgii/cidsi-backend.git
```
Ingresar en la carpeta
```
cd cidsi-backend
```
Iniciar el servicio
```
node server/server.js
```
Servicio para registrar asistentes
```
http://localhost:3000/newRegister
POST
{
"nombre":"alguie",
"email":"alguei@aog.com",
"celular":"1234567",
"tallera":"",
"tallerb":"",
}
```
Probar con curl
```
curl -A "Mozilla/5.0" -X POST http://localhost:3000/newRegister -H "Content-Type: application/json" --data '{"nombre":"Alguien 1","email":"alguien1@alguien.com","celular":"12345678","tallera":"taller1","tallerb":"taller3"}'
```
Habilitar Proxy reverso en apache2
```
sudo a2enmod proxy_htttp
```
Agregar las lineas en la configuracion del sitio .conf
```
ProxyPass "/eventos/cidsi2018/api/" "http://localhost:3000/"
ProxyPassReverse "/eventos/cidsi2018/api/" "http://localhost:3000/"
```
Agregar el backend al Servicio pm2, dentro de la carpeta principal
```
env NODE_ENV=production pm2 start server/server.js --name cidsi-backend
```
Agregar paquetes restantes, dentro de la carpeta
```
npm install
```
## Conferencia Internacional de Seguridad Informática
Backend del Sitio Web organizado por el CGII
\ No newline at end of file
{
"name": "cidsi-2018",
"version": "1.0.0",
"description": "Congreso Internacional de Seguridad Informatica.",
"main": "server/server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server/server.js"
},
"author": "Edson Sosa",
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.3",
"express": "^4.16.3",
"mongoose": "^5.2.16",
"mongoose-unique-validator": "^2.0.1",
"mongose": "0.0.2-security",
"nodemailer": "^4.6.8",
"pkg": "^4.3.4",
"qrcode": "^1.3.0"
}
}
{
"correo":{
"origen":"[correo electronico]",
"host":"[smtp_server]",
"port":"[port]",
"secure":false,
"ignoreTLS":false,
"auth":{
"user":"[user_correo_electronico]",
"pass":"[contraseña de correo electronico]"
},
"tls":{
"rejectUnauthorized":false
}
}
}
//=======================================
// Puerto de conexion
//=======================================
process.env.PORT= process.env.PORT || 3000;
/*
==========================
Entorno
==========================
*/
process.env.NODE_ENV=process.env.NODE_ENV || 'dev';
let urlDB;
//if(process.env.NODE_ENV==='dev'){
if(process.env.NODE_ENV==='dev' || process.env.NODE_ENV==='production'){
urlDB = 'mongodb://localhost:27017/cidsidb';
}else{
urlDB=process.env.MONGO_URI;
}
process.env.URLDB=urlDB;
const mongoose = require('mongoose');
const uniqueValidator = require('mongoose-unique-validator');
let Schema = mongoose.Schema;
let estados={
values:['registrado','activado','confirmado','no-confirmado','registro-manual'],
message:'{VALUE} no es un codigo valido.'
}
let registroSchema = new Schema({
codigo:{
type:String,
required:[true,'Código de activacion requerido.']
},
nombre:{
type:String,
required:[true,'El nombre es requerido.']
},
ci:{
type:String,
required:[true,'El carnet de identidad es requerido.']
},
email:{
type:String,
unique:true,
required:[true,'El email es requerido.']
},
celular:{
type:String,
required:[true,'El número de celular es requerido.']
},
residencia:String,
nivel:String,
universidad_trabajo:String,
estado:{
type:String,
enum:estados
},
fecha_registro:{
type: Date,
default: Date.now
},
tipo:String,
taller1:Boolean,
taller2:Boolean,
taller3:Boolean,
taller4:Boolean,
taller5:Boolean,
bus_dia1:Boolean,
fecha_bus_dia1:Date,
bus_dia2:Boolean,
fecha_bus_dia2:Date,
bus_dia3:Boolean,
fecha_bus_dia3:Date,
asistencia_dia1:Boolean,
fecha_dia1:Date,
asistencia_dia2:Boolean,
fecha_dia2:Date,
asistencia_dia3:Boolean,
fecha_dia3:Date,
asistencia_ctf:Boolean,
fecha_ctf:Date,
asistencia_taller1:Boolean,
fecha_taller1:Date,
asistencia_taller2:Boolean,
fecha_taller2:Date,
asistencia_taller3:Boolean,
fecha_taller3:Date,
asistencia_taller4:Boolean,
fecha_taller4:Date,
asistencia_taller5:Boolean,
fecha_taller5:Date
});
registroSchema.plugin(uniqueValidator, {message: '{PATH} debe ser unico'});
module.exports = mongoose.model('Registro', registroSchema);
const express = require('express');
const app = express();
app.use(require('./register_routes'));
module.exports = app;
This diff is collapsed.
require('./config/config');
const express = require('express');
const app = express();
const mongoose = require('mongoose');
//Body Parser
const bodyParser = require('body-parser');
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
//res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Methods', 'POST');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
//Importamos la clase q contiene todas las clases q maneja las rutas disponibles (index_classes_routes).
app.use(require('./routes/index_classes_routes'));
//Conectamos a mongo DB con mongoose
mongoose.connect(process.env.URLDB, { useNewUrlParser: true },(err,resp)=>{
if(err) throw err;
console.log('Base de datos ONLINE'.green);
});
app.listen(process.env.PORT,()=>{
console.log(`Escuchando el puerto ${process.env.PORT}`);
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment