Skip to content

Commit

Permalink
endpoint: templates now supports url_args passed in from matching tem…
Browse files Browse the repository at this point in the history
…plate_route.url_pattern

closes #137
  • Loading branch information
erichanson committed Apr 7, 2019
1 parent 8b02276 commit 27e7690
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 1 addition & 3 deletions bin/logs.sh
Original file line number Diff line number Diff line change
@@ -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; }
14 changes: 11 additions & 3 deletions src/pg-extension/endpoint/001-server.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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'");
Expand Down

0 comments on commit 27e7690

Please sign in to comment.