-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
108 lines (88 loc) · 2.74 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Hola mundo
var express = require('express');
var expressLayouts = require('express-ejs-layouts');
var bodyParser = require('body-parser'); // Para poder leer JSON mediante request.
var mailer = require('nodemailer'); // Envio de correo electrónico
var fs = require('fs');
var app = express();
var port = 3000;
app.set('view engine','ejs');
app.use( expressLayouts );
app.use( bodyParser.json() );
// Configuración de correo electrónico
var transporter = mailer.createTransport({
host: 'smtp.google.com',
secureConnection: false,
service: 'gmail',
auth: {
user: '',
password: ''
}
});
// Mensaje y a quien
var mailOptions = {
from: '"Positive C 👻" <[email protected]>', // sender address
to: '[email protected]', // list of receivers
subject: 'Hello ✔', // Subject line
text: 'Hello world ?', // plain text body
html: '<b>Hello world ?</b>' // html body
};
//Referencia
var router = require('./app/routes');
app.use('/',router);
// Montar /home para cualquier request.
app.use('/home', express.static(__dirname + '/public'));
// Use of statics
app.use(express.static(__dirname + '/public')); //Carpeta de funcionamiento
// Registro-envio de correo
app.post('/register-send-mail',function (request, response) {
console.log( "Tu solicitud fue: " + request.body.nombre );
response.send("Se envió la solicitud de: " + request.body.email );
// Enviar el correo:
// transporter.sendMail(mailOptions, (error, info) => {
// if (error) {
// return console.log(error);
// }
// console.log('Message %s sent: %s', info.messageId, info.response);
// });
});
app.get('/users/type=:type',function(request, response){
fs.readFile('app/users.json','utf8',function( err, data ){
if (err) {
console.log( err );
response.redirect('/404');
}
var x = repartirInfo( JSON.parse(data), request.params.type );
if ( x == null ) {
response.redirect('/404');
}
else{
response.json( x );
}
});
});
function repartirInfo( data, mode ){
var perm = {};
perm['Operaciones'] = data['Operaciones'];
perm['Información'] = data['Información'];
perm['Maestros'] = data['Maestros'];
switch ( mode ) {
case "superuser":
case "company":
perm['Finanzas'] = data['Finanzas'];
break;
case "normal":
break;
default:
perm = null;
}
return perm;
}
app.get('*', function(req, res){
res.redirect('/404');
});
//Servidor
app.listen(port, function () {
console.log("Inicializado Backoffice");
console.log("Escuchando en puerto 3000");
});