There is an undocumented feature where you can add custom paths to a web app url for routing (and you can reference that path via the 'pathInfo' property on the event object). But you'll have to pass a user access token with the request (for both GET and POST) regardless of the settings used to deploy the web app.
Thursday, January 23, 2020 Alex wrote:
You can pass it as a url variable ("access_token=[ACCESS_TOKEN_VALUE]") when making requests to the web url or in the Authorization header as a Bearer token. I'm not sure, but the last time I played with it, it seemed that only the owner of the script could access routing this way, so its probably not something you can scale to multiple users.
function doGet(e) { var parameters = e.parameters; return Router(parameters); }
function Router(parameters) { var view, id;
view = 'v' in parameters ? parameters.v[0] : null ; id = 'id' in parameters ? parameters.id[0] : null;
switch (view) { case 'orders': return loadOrders(); case 'view_order': return loadOrder(id);
default: return loadOrders(); }}
function loadOrders() {
var orderData = getUpcomingOrders(); var orders = orderData.orders;
return render("Views/Pages/Orders/index", { orders: orders });
}
function loadOrder(id) {
var orderData = getOrder(id); var order = createOrderObj(orderData);
return render("Views/Pages/View_Order/index", { order: order, });}
function render(file, argsObject){ var html = HtmlService.createTemplateFromFile(file);
if(argsObject) { var keys = Object.keys(argsObject); keys.forEach(function(key){ html[key] = argsObject[key]; }); } return html.evaluate().setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);}
Do you mean having the code do something different depending upon some value being passed to it?
There is an undocumented feature where you can add custom paths to a web app url for routing
I'm not sure what Alex meant by "use a router?"
function doPost(e){
var router = new Route(e);
router.matches(); // <== the rules for checkers
return router
.on(checker, callback)
.on(checker, callback)
.resolve();
}