Skip to content
Permalink
Browse files

endpoint: templates now supports url_args passed in from matching tem…

…plate_route.url_pattern

closes #137
  • Loading branch information...
erichanson committed Apr 7, 2019
1 parent 8b02276 commit 27e769031ddfb73837a29bc5fc549a7bd3227d90
Showing with 12 additions and 6 deletions.
  1. +1 −3 bin/logs.sh
  2. +11 −3 src/pg-extension/endpoint/001-server.sql
@@ -1,3 +1 @@
tail -f /var/log/postgresql/postgresql-10-main.log &
tail -f /var/log/nginx/aquameta_db.*.log &
journalctl -u aquameta.emperor.uwsgi.service -f &
{ tail -f /var/log/postgresql/postgresql-10-main.log /var/log/nginx/aquameta_db.*.log & journalctl -u aquameta.emperor.uwsgi.service -f; }
@@ -2181,25 +2181,33 @@ $$ language plpythonu;
create or replace function endpoint.template_render(
template_id uuid,
route_args json default '{}',
url_args json default '{}'
url_args json default '[]'
) returns text as $$


// fetch the template
var template;
try {
var template_rows = plv8.execute('select * from endpoint.template where id=$1', [ template_id ]);
template = template_rows[0];
// plv8.elog(NOTICE, ' template is ' + template.id);
plv8.elog(NOTICE, ' template is ' + template.id);
}
catch( e ) {
plv8.elog( ERROR, e, e)
return false;
}
// plv8.elog(NOTICE, 'template '+template.name+' called with route_args '+JSON.stringify(route_args)+', url_args'+JSON.stringify(url_args));



// setup javascript scope
var context = {};
// route_args is an object passed in from route.args json
for (var key in route_args) { context[key] = route_args[key]; }
for (var key in url_args) { context[key] = url_args[key]; }
// url_args is an array of vals extracted from the matching url_pattern
context.url_args = url_args;
plv8.elog(NOTICE, 'context set to '+JSON.stringify(context));


// eval datum-plv8
var datum_rows = plv8.execute("select * from widget.dependency_js where name='datum-plv8'");

0 comments on commit 27e7690

Please sign in to comment.
You can’t perform that action at this time.