forked from BrunoRamirezG/HackTheOcean-Front
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
62 lines (53 loc) · 1.94 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
const mysql = require('mysql');
const express = require('express');
var cors = require('cors');
const path = require('path');
const app = express()
const port = 8080
var conn=mysql.createConnection({host:"hackocean.mysql.database.azure.com", user:"daniel", password:"password1.0", database:"oceanhack", port:3306});
conn.connect((err)=>{
if(err){
console.log('Error in DB Connection');
throw err;
} else{
console.log('Connected to the DB!');
}
})
app.use(cors());
app.use(express.static(__dirname + '/public'));
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname, '/public/index.html'));
});
app.get('/zgolfo', function(req, res) {
res.sendFile(path.join(__dirname, '/public/zgolfo.html'));
});
app.get('/zpacifico', function(req, res) {
res.sendFile(path.join(__dirname, '/public/zpacifico.html'));
});
app.get('/region1', (req, res) => {
//res.send('Hello World!')
conn.query(`SELECT es.nombre_especie, e.es_endemica, e.es_amenazada, e.fecha_inicio_veda, fecha_fin_veda FROM espregprod as e, especies as es WHERE e.id_especie=es.id_especie AND id_region='1';`, function (err, result) {
console.log(JSON.stringify(result));
if (err || result[0] == undefined){
res.send('{"mensaje":"error db"}');
throw err;
} else{
res.send(JSON.stringify(result));
}
});
})
app.get('/region2', (req, res) => {
//res.send('Hello World!')
conn.query(`SELECT es.nombre_especie, e.es_endemica, e.es_amenazada, e.fecha_inicio_veda, fecha_fin_veda FROM espregprod as e, especies as es WHERE e.id_especie=es.id_especie AND id_region='2';`, function (err, result) {
console.log(JSON.stringify(result));
if (err || result[0] == undefined){
res.send('{"mensaje":"error db"}');
throw err;
} else{
res.send(JSON.stringify(result));
}
});
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})