Commit 01029e0d authored by Rodrigo Tapia-McClung's avatar Rodrigo Tapia-McClung

Remove '/data' in routes and calls

parent afc95448
......@@ -56,7 +56,7 @@ const sql = (params, query) => {
/**
* @swagger
*
* /data/geobuf/{table}:
* /geobuf/{table}:
* get:
* description: return table as geobuf
* tags: ['geodata']
......@@ -93,7 +93,7 @@ const sql = (params, query) => {
* 422:
* description: invalid datasource or columnname
*/
app.get('/data/geobuf/:table', async (req, res)=> {
app.get('/geobuf/:table', async (req, res)=> {
if (!req.query.geom_column) {
req.query.geom_column = 'geom';
}
......
......@@ -56,7 +56,7 @@ module.exports = function(app, pool) {
/**
* @swagger
*
* /data/geojson/{table}:
* /geojson/{table}:
* get:
* description: return table as geojson
* tags: ['geodata']
......@@ -93,7 +93,7 @@ module.exports = function(app, pool) {
* 422:
* description: invalid datasource or columnname
*/
app.get('/data/geojson/:table', async (req, res) => {
app.get('/geojson/:table', async (req, res) => {
if (!req.query.geom_column) {
req.query.geom_column = 'geom';
}
......
......@@ -44,7 +44,7 @@ const sql = () => {
/**
* @swagger
*
* /data/list_layers:
* /list_layers:
* get:
* description: get list of available tables
* tags: ['meta']
......@@ -88,7 +88,7 @@ const sql = () => {
* 500:
* description: unexpected error
*/
app.get('/data/list_layers', async (req, res)=>{
app.get('/list_layers', async (req, res)=>{
try {
const sqlString = sql()
const result = await pool.query(sqlString);
......
......@@ -108,7 +108,7 @@ module.exports = function(app, pool, cache) {
/**
* @swagger
*
* /data/{datasource}/mvt/{z}/{x}/{y}:
* /{datasource}/mvt/{z}/{x}/{y}:
* get:
* description: get mapbox vector tile (mvt)
* tags: ['geodata']
......@@ -157,7 +157,13 @@ module.exports = function(app, pool, cache) {
* 422:
* description: invalid datasource or columnname
*/
app.get('/data/:datasource/mvt/:z/:x/:y', cacheMiddleWare, async (req, res)=>{
app.get('/:datasource/mvt/:z/:x/:y', cacheMiddleWare, async (req, res)=>{
var types = require('pg').types
types.setTypeParser(1700, function(val) {
return parseFloat(val);
});
if (!req.query.geom_column) {
req.query.geom_column = 'geom'; // default
}
......
......@@ -166,10 +166,12 @@ const sortInitialDateAscending = (a, b) => {
return a - b;
}
const baseUrl = new URL(window.location.href).origin; // returns "http://localhost:8090"
// use `${baseUrl}/something`
// query available dates on DB
const setupDates = () => {
return new Promise(resolve => {
const baseUrl = new URL(`/data`, window.location.href).href;
let layersQuery = `${baseUrl}/list_layers`;
d3.json(layersQuery).then(layers => {
layers.forEach(layer => {
......@@ -405,7 +407,6 @@ const queryFiles = () => {
const getMinMax = table => {
return new Promise(resolve => {
const baseUrl = new URL(`/data`, window.location.href).href;
let minmaxQuery = `${baseUrl}/query/${table}?columns=${cols.join(", ")}`;
d3.json(minmaxQuery).then(minmax => {
resolve(minmax[0]);
......@@ -648,7 +649,6 @@ const updateCharts = async() => {
// define MVT layer for given month table and all indicators
const mapboxLayer = (monthYear) => {
const baseUrl = new URL(`/data`, window.location.href).href;
let pbfLayer = {
id: monthYear,
source: {
......
......@@ -17,10 +17,12 @@ let timeDimensionControl,
layerControl,
tiles;
const baseUrl = new URL(window.location.href).origin; // returns "http://localhost:8090"
// use `${baseUrl}/something`
const getMinMax = table => {
return new Promise(resolve => {
//let table = "urbanization_year";
const baseUrl = new URL(`/data`, window.location.href).href;
let minmaxQuery = `${baseUrl}/query/${table}?columns=${`min(yeartrimes), max(yeartrimes)`}`;
d3.json(minmaxQuery).then(minmax => {
resolve(minmax[0]);
......
......@@ -63,7 +63,8 @@ d3.json("https://unpkg.com/d3-time-format@2.1.1/locale/es-MX.json").then(async l
const sortInitialDateAscending = (a, b) => a - b;
// Dates will be cast to numbers automagically:
const baseUrl = new URL(`/data`, window.location.href).href;
const baseUrl = new URL(window.location.href).origin; // returns "http://localhost:8090"
// use `${baseUrl}/something`
// query available dates on DB
const setupDates = () => {
......
......@@ -6,7 +6,7 @@
*/
/* globals Promise */
/* exported layerControl */
/* exported layerControl, baseUrl */
let timeDimensionControl,
map,
......@@ -17,10 +17,11 @@ let timeDimensionControl,
layerControl,
tiles;
const baseUrl = new URL(window.location.href).origin; // returns "http://localhost:8090"
// use `${baseUrl}/something`
const getMinMax = table => {
return new Promise(resolve => {
//let table = "urbanization_year";
const baseUrl = new URL(`/data`, window.location.href).href;
let minmaxQuery = `${baseUrl}/query/${table}?columns=${`min(yeartrimes), max(yeartrimes)`}`;
d3.json(minmaxQuery).then(minmax => {
resolve(minmax[0]);
......@@ -223,7 +224,6 @@ const populateMap = async(mapData) => {
// define MVT layer for given table and all trimester column
const mapboxLayer = (table) => {
const baseUrl = new URL(`/data`, window.location.href).href;
let pbfLayer = {
id: table,
source: {
......
......@@ -5,7 +5,7 @@
* June 2020 - March 2021
*/
/* globals am4core, am4charts, am4themes_animated */
/* globals am4core, am4charts, am4themes_animated, baseUrl */
// amchart
am4core.ready(function() {
......@@ -116,7 +116,6 @@ am4core.ready(function() {
}
//Add data
const baseUrl = new URL(`/data`, window.location.href).href;
let table = "urbanization_year";
let query = `${baseUrl}/query/${table}?columns=yeartrimes,sum(area)/10000 as area,date&group=yeartrimes,date&sort=yeartrimes`;
d3.json(query).then( d => {
......
......@@ -5,7 +5,7 @@
* August-September 2019
*/
/* globals map, userFiles, userDates, indicators, indicatorVars, indicatorsNames */
/* globals map, userFiles, userDates, indicators, indicatorVars, indicatorsNames, baseUrl */
/* exported makeIndicatorGraph, getData, updateData, getDataInSelection */
let minDate, maxDate, xLine, yLine;
......@@ -26,7 +26,6 @@ const getData = async () => {
data[indicator].push({name: `${indicator}0`, values: []});
});
const baseUrl = new URL(`/data`, window.location.href).href;
const userFilePromises = userFiles.map( async monthYear => {
let queryDB = `${baseUrl}/query/${monthYear}?columns=${queryColumns.join(",")}`;
const dbData = await d3.json(queryDB);
......@@ -57,8 +56,6 @@ const getDataInSelection = async () => {
data[indicator] = [];
});
const baseUrl = new URL(`/data`, window.location.href).href;
// Convert drawn items to GeoJSON and check what's inside each one of them
const drawnItemPromises = drawnItems.toGeoJSON().features.map( async (item, i) => {
// set SRID fro drawn features
......
......@@ -6,7 +6,7 @@
*/
/* globals omnivore, Promise, chroma, makeBaseMap, makeIndicatorGraph, getData, getDataInSelection */
/* exported indicators. userFiles, userDates, timeParse, layerControl, updateCharts */
/* exported indicators. userFiles, userDates, timeParse, layerControl, updateCharts, baseUrl */
let timeParse,
timeFormat,
......@@ -96,10 +96,12 @@ const sortInitialDateAscending = (a, b) => {
return a - b;
}
const baseUrl = new URL(window.location.href).origin; // returns "http://localhost:8090"
// use `${baseUrl}/something`
// query available dates on DB
const setupDates = () => {
return new Promise( resolve => {
const baseUrl = new URL(`/data`, window.location.href).href;
let layersQuery = `${baseUrl}/list_layers`;
d3.json(layersQuery).then(layers => {
layers.forEach(layer => {
......@@ -332,7 +334,6 @@ const queryFiles = () => {
const getMinMax = table => {
return new Promise( resolve => {
const baseUrl = new URL(`/data`, window.location.href).href;
let minmaxQuery = `${baseUrl}/query/${table}?columns=${cols.join(", ")}`;
d3.json(minmaxQuery).then( minmax => {
resolve(minmax[0]);
......@@ -535,7 +536,6 @@ const updateCharts = async () => {
// define MVT layer for given month table and all indicators
const mapboxLayer = (monthYear) => {
const baseUrl = new URL(`/data`, window.location.href).href;
let pbfLayer = {
id: monthYear,
source: {
......
......@@ -5,7 +5,7 @@
* August-September 2019
*/
/* global baseFileSize, formatBytes, Promise, omnivore, JSZip, map, glmap, layerControl, updateCharts */
/* global baseFileSize, formatBytes, Promise, omnivore, JSZip, map, glmap, layerControl, updateCharts, baseUrl */
/* exported makeBaseMap, baseLayerPromises, drawnItems */
/* Lines related to displaying loading bar are commented */
......@@ -518,7 +518,6 @@ let layer_agebsbydens = new L.geoJson(null, {
style: style_agebsbydens
});
const baseUrl = new URL(`/data`, window.location.href).href;
let layer_agricolapv_fake = new L.geoJson(null, {}),
layer_agricolaoi_fake = new L.geoJson(null, {});
......
......@@ -6,7 +6,7 @@
*/
/* globals omnivore, Promise, chroma, makeBaseMap, makeIndicatorGraph, getData, getDataInSelection */
/* exported indicators. userFiles, userDates, timeParse, layerControl, updateCharts */
/* exported indicators. userFiles, userDates, timeParse, layerControl, updateCharts, baseUrl */
let timeParse,
timeFormat,
......@@ -96,10 +96,12 @@ const sortInitialDateAscending = (a, b) => {
return a - b;
}
const baseUrl = new URL(window.location.href).origin; // returns "http://localhost:8090"
// use `${baseUrl}/something`
// query available dates on DB
const setupDates = () => {
return new Promise( resolve => {
const baseUrl = new URL(`/data`, window.location.href).href;
let layersQuery = `${baseUrl}/list_layers`;
d3.json(layersQuery).then(layers => {
layers.forEach(layer => {
......@@ -332,7 +334,6 @@ const queryFiles = () => {
const getMinMax = table => {
return new Promise( resolve => {
const baseUrl = new URL(`/data`, window.location.href).href;
let minmaxQuery = `${baseUrl}/query/${table}?columns=${cols.join(", ")}`;
d3.json(minmaxQuery).then( minmax => {
resolve(minmax[0]);
......@@ -535,7 +536,6 @@ const updateCharts = async () => {
// define MVT layer for given month table and all indicators
const mapboxLayer = (monthYear) => {
const baseUrl = new URL(`/data`, window.location.href).href;
let pbfLayer = {
id: monthYear,
source: {
......
......@@ -27,7 +27,7 @@ module.exports = function(app, pool) {
/**
* @swagger
*
* /data/query/{table}:
* /query/{table}:
* get:
* description: Query a table or view.
* tags: ['api']
......@@ -69,7 +69,7 @@ module.exports = function(app, pool) {
* 422:
* description: invalid table or column name
*/
app.get('/data/query/:table', async (req, res)=> {
app.get('/query/:table', async (req, res)=> {
const sqlString = sql(req.params, req.query);
try {
const result = await pool.query(sqlString);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment