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