Play framework: Dynamic routing depending on version number - dynamic

I'm trying to dynamically define a version in the URI routing.
My immidiate ideas were to
a)
I've configured in the application.conf a row stating my current version:
myApp.ver = 0.1
I wan't to use it in the routes file as part of the URI, for example:
GET /myApp/{version}/welcome controller.myApp.Welcome()
The idea is not to pass the version number to the Welcome() method
but to get the version from the application.conf file.
I've searched for defining parameters in the route file but didn't find information that helped me.
b) Another idea was to have a variable in the routes, something like:
CurrentVersion = 0.1
in the routes file and use it in the URI.
How can I solve this? I havn't found an example for this.
Thanks.

If you want to do this for every route, it should be possible to set the application.baseUrl to include your version number. To do this conveniently you can define the version in your application.conf instead of the Build.scala file, as described here.
myApp.name = myApp
myApp.ver = 0.1
application.baseUrl = ${myApp.name}/${myApp.ver}
If you want to do it only for some routes, there doesn't seem to be a simple solution. If you could ignore parameters in routes, I'd say use a regexp parameter and verify it in your global router - unfortunately this doesn't seem possible without passing the parameter to the controller.
So I see two other options:
Hardcode the version number in the routes file and do a search and replace every time it changes.
Create a plugin for the sbt build process and let it replace the version in your routes file.

In Play 1.2.x, in your conf/routes file, add a route like this:
GET /myApp/${play.configuration.getProperty("myApp.ver")}/welcome myApp.Welcome()

Related

How to pass the scopes I need in the microsoftTeams.authentication.authenticate() method

After creating a teams-tab-app using the vscode teams toolkit, I see that in the default auth-start.html file the script tries to extract the scopes from the URL (that was constructed by the microsoftTeams.authentication.authenticate() method), however I don't see any reference in the documentation on how to pass these scopes in this method.
Does anyone know how to pass these scopes?
I've wondered about this myself when looking at a toolkit, but I haven't used it for any production systems so never bothered to look too deep. I do see that in useTeamsFx.tsx is where it's doing the redirect to startLoginPageUrl, so presumably you need to set REACT_APP_START_LOGIN_PAGE_URL to be the path to the auth-start.html, so you could set it to include a querystring as well. It needs the app Id so you'd need to set that as well, but the useTeamsFx also wants REACT_APP_CLIENT_ID which you'd set as well. As a result, it might make sense to store the scopes you want in your code or in an environment variable as well, and then compose the value you send to initiateLoginEndpoint. Basically, instead of
var startLoginPageUrl = process.env.REACT_APP_START_LOGIN_PAGE_URL;
...
initiateLoginEndpoint: startLoginPageUrl
...
you might instead make it
var startLoginPageUrl = process.env.REACT_APP_START_LOGIN_PAGE_URL;
var scopes = process.env.REACT_APP_SCOPES; // <-- this is added
...
initiateLoginEndpoint: `${startLoginPageUrl}?clientId=${clientId}&scope=${scopes}`
...
but this is untested, so no guarantees.
On a separate but related note, in my sample project, in auth-start, it refers to a very old version of MicrosoftTeams.min.js (v 1.6, and current is 1.11). I might just have a very old Teams Toolkit, but maybe not...

Writing an object to the location.hash using Vue.js and URI.js

I have a list of items along with a filter. I'd like to store the filter options in the window.location.hash property, so that I have nice sharable urls.
I am struggling to build a hash fragment which will work, using URI.js.
Vue.js 2.4.4
URI.js 1.19.0
What I've done so far
import Uri from "urijs";
let UriFragment = require('../../node_modules/urijs/src/URI.fragmentURI.js');
// UpdateHash method
let uri = new Uri(window.location.href);
uri.fragment({
providers: ['best', 'bestest'],
sort: 'recommended'
});
window.location.hash = uri.fragment();
What's happening?
example.com/list-of-things#![object Object]
What I expected to happen
As per the docs about 'fiddling with the fragment' http://medialize.github.io/URI.js/
example.com/list-of-things#providers=best&providers=bestest&sort=recommended
Question
How can I ensure that the plugin for URI.js is loaded and working? Then move onto figuring out why it's not outputting a formatted uri fragment.
I knew as soon as I posted, I would find the answer.
I was trying to use code for URI.fragmentURI.js when in fact I wanted URI.fragmentQuery.js.
Swapping to the correct plugin for the library has solved this problem.

How to apply metadata to all files in a content directory

I have a content directory called foo and I want all files under that directory to have an extra metadata item foovar: default, unless explicitly overridden in the file header. I think I'm supposed to do this with EXTRA_PATH_METADATA, but I can't figure out what incantation it wants.
(for my current use case I'm trying to apply template: sometemplate within this dir, but I'm interested in solving the general case as it would make several related headaches go away)
I think what you're looking for is actually DEFAULT_METADATA. Check out this portion of the documentation:
DEFAULT_METADATA = {}
The default metadata you want to use for all articles and pages.
So, in your case it might look something like this in your config file:
DEFAULT_METADATA = {'foovar': 'default'}
Then to assign your custom template(s), see this portion of the documentation.
This wasn't possible at the time I asked. I've since sent the devs a PR adding support, and it's been merged to master. Presumably it will go out in the next release. It makes EXTRA_PATH_METADATA recursive, so you can apply settings to a subdir like this:
EXTRA_PATH_METADATA = {'dirname/subdir': {'status': 'hidden'}}

Recursive/Exploded uri variable with restlet

Does Restlet support exploded path variable (reference to URI Template RFC)?
An example would be /documents{/path*} where path can be for example "a/b/c/d/e".
This syntax doesn't seem to work with Restlet.
I'm creating a folder navigation api and I can have variable path depth, but I'm trying to have only one resource on the server side to handle all the calls. Is this something I can do with Restlet? I suppose I could create a custom router but if there is another way to do this I would like to know.
Thanks
It is possible to support this using matching modes.
For example:
myRouter.attach("/documents{path}",
MyResource.class).setMatchingMode(Template.START_WITH);
Hope this helps!
I'm doing the following
myRouter.attach("/documents/{path}", MyResource.class).setMatchingMode(Template.START_WITH);
Now I do get inside the resource GET method, but if I request the value of the path variable, I only get the first part (for example, /documents/a/b/c, path returns "a".) I use getRequest().getAttributes().get("path") to retrieve the value. Am I doing something wrong ?
Mathieu

Rails 3 Routes - prepend all url paths with set string

I've been asked to change the routes on a Rails project such that the routes will only respond to requests where the app name (or other arbitrary string) is the first string after the domain name, e.g.
www.thething.com/appname/users/sign_in instead of www.thething.com/users/sign_in
www.thething.com/appname instead of www.thething.com
www.thething.com/appname/search instead of www.thething.com/search
I've suggested using a subdomain appname.thething.com instead, but the client is quite specific about wanting the URL in the above format.
www.thething.com will be a splash page which will contain a link to www.thething.com/appname, with the intention of adding additional apps/pages in future with new folder names.
Is there an easy way of modifying the routes file so that all routes will get the .../appname prepended to all resources and routes, while being after the domain?
One option is wrap all existing routes in: namespace :appname do ... end, like so:
# config/routes.rb
Appname::Application.routes.draw do
namespace :appname do
# existing routes go here
end
end
I'm not sure if this is the most elegant solution, but it will prepend /appname to all the routes.