2019-01-31 16:32:34 -05:00
|
|
|
require('dotenv').config();
|
2019-01-31 14:19:42 -05:00
|
|
|
const express = require('express');
|
|
|
|
const server = express();
|
2019-01-31 16:32:34 -05:00
|
|
|
const pg = require('pg');
|
|
|
|
|
|
|
|
var Postgres = new pg.Client({
|
|
|
|
user: process.env.user,
|
|
|
|
password: process.env.password,
|
|
|
|
host: process.env.host,
|
|
|
|
port: process.env.port,
|
|
|
|
database: process.env.database,
|
|
|
|
ssl: false,
|
|
|
|
application_name: "osm_api"
|
|
|
|
});
|
|
|
|
Postgres.connect();
|
|
|
|
|
|
|
|
Postgres.FirstRow = function(inSQL,args, inResponse)
|
|
|
|
{
|
|
|
|
Postgres.query(inSQL,args, (err, res) => {
|
|
|
|
if (err === null)
|
|
|
|
{
|
|
|
|
inResponse.json(res.rows[0]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
inResponse.json(err.stack);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
server.get('/list_sources', function (req,res) {
|
|
|
|
var sql = "select jsonb_agg(defn) from tps.srce";
|
|
|
|
console.log(req.query);
|
|
|
|
Postgres.FirstRow(sql,[],res);
|
|
|
|
})
|
|
|
|
|
|
|
|
server.get('/', (req,res) => res.send('its running yay 🎡'))
|
2019-01-31 14:19:42 -05:00
|
|
|
|
|
|
|
server.listen(3000,() => console.log('started'))
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = server;
|