-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
158 lines (130 loc) · 3 KB
/
app.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
var express = require('express');
// var _ = require('underscore');
var cors = require('cors');
var bodyParser = require('body-parser');
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: '[email protected]',
pass: 'Haklab123'
}
});
var mailOptions = {
from: 'Nodara ✔ <[email protected]>', // sender address
to: '[email protected]', // list of receivers
subject: '[javascripting] JS radionica', // Subject line
text: 'Hvala sto ste bili na radionici...NOT ✔', // plaintext body
html: '<b>Hvala sto ste bili na radionici...NOT ✔</b>' // html body
};
var app = express();
app.use(bodyParser.json({
limit: 10000000
}));
app.use(bodyParser.urlencoded({
extended: true,
limit: 10000000
}));
app.use(cors());
app.set('port', (process.env.PORT || 5000));
app.get('/', function(req, res) {
res.send("Hello");
});
var currentId = 3;
var radionice = [
{
id: 0,
ime: "javascript",
mesto: "hklbgd"
},
{
id: 1,
ime: "os",
mesto: "hklbgd"
},
{
id: 2,
ime: "elektronika",
img:"http://www.alsglobal.com/~/media/Images/Divisions/Life%20Sciences/Electronics%20Testing/Electronics%204.jpg",
mesto: "hklbgd"
}
];
app.get('/radionice', function(req, res) {
res.json(radionice);
});
app.get('/radionice/:id', function(req, res) {
var id = Number(req.params.id), radionica;
//TODO dodaj underscore
console.log(id);
for (var i in radionice) {
if (radionice[i].id === id) {
radionica = radionice[i];
}
}
res.json(radionica);
});
//TODO zameni sa post
app.post('/test', function(req, res) {
req.on('data', function(ddd) {
console.log(ddd);
});
var radionica = {
id: currentId,
ime: req.query.ime,
mesto: "haklab"
};
console.log(radionica);
currentId++;
radionice.push(radionica);
});
// EVENTS
var currEventId = 3;
var events = [
{
id: 0,
ime: "event0",
mesto: "hklbgd"
},
{
id: 1,
ime: "event1",
mesto: "hklbgd"
},
{
id: 2,
ime: "event2",
img:"https://upload.wikimedia.org/wikipedia/sh/d/d9/Radno_Predsednistvo_Pete_konferencije_KPJ_1952_god.jpg",
mesto: "hklbgd"
}
];
app.get('/events', function(req, res) {
res.json(events);
});
app.get('/events/:id', function(req, res) {
var id = Number(req.params.id), event;
//TODO dodaj underscore
console.log(id);
for (var e in events) {
if (events[e].id === id) {
event = events[e];
}
}
res.json(events);
});
//TODO zameni sa post
app.post('/send', function(req, res) {
var data = req.body;
data.sent = true;
transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log(error);
}else{
console.log('Message sent: ' + info.response);
}
res.json(data);
});
});
// HTTP - get (citanje), post (kreiranje), put (modifikacija), delete (brisanje)
app.listen(app.get('port'), function() {
console.log("server has stared on port 5000");
});