-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (50 loc) · 1.71 KB
/
index.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
let config = require("./public/config");
var mysql = require('mysql');
var pool = mysql.createPool(config);
const fs = require('fs');
const express = require('express');
const path = require('path');
const PORT = process.env.PORT || 5000;
// ...
express()
.use(express.static(path.join(__dirname, 'public')))
.use('/static', express.static('public'))
//.set('views', path.join(__dirname, 'views'))
// .set('view engine', 'ejs')
.get('/', (req, res) => res.render('pages/index'))
.get('/getcombo', async (req, res) => {
let getcombo = await require('./public/get_combos_html.js');
res.send(getcombo);
})
// .get('/getappcombos', async (req, res) => {
// let getcombo = await require('./public/get_app_combos');
// res.send(getcombo);
// })
.get('/getcombosfromdb', async (req, res) => {
let getcombo = await require('./public/getcombdatafromdb.js');
res.status(200).send(getcombo);
// res.send(getcombo);
})
.get('/getappcombos', async function (req, res, next) {
let getcombo = await require('./public/getcombdatafromdb.js');
var context = {};
let lat = req?.query?.lat;
let lon = req?.query?.lon;
let sort = req?.query?.sort;
console.log(`lat = ${lat}, lon = ${lon}, sort = ${sort}`);
let qry = `call ComboWithOptions(NULL, NULL, ${sort});`;
if (lat && lon) {
qry = `call ComboWithOptions(${lat}, ${lon}, ${sort});`;
}
console.log(`Query: ${qry}`);
pool.query(qry, function (err, rows, fields) {
if (err) {
next(err);
return;
}
//context.results = JSON.stringify(rows);
//console.log(rows);
res.status(200).send(rows[0]);
});
})
.listen(PORT, () => console.log(`Listening on ${PORT}`));