This article provides an overview of the different URLs you can use to access your Web App, as well as some options if you'd like to append parameters in your URL.
Contents
App URLs
Using parameters in URLs
Examples
Summary
App URLs
1) The official app URL:
http://<your-domino-url>/modelproducts/<app_id>
This URL will not ever change for an app. Going to this URL in a browser gives you your app with a Domino banner at the top.
2) The "static" internal app URL:
http://<your-domino-url>/u/<user>/<project>/app
Like the first URL, this URL will not change if you stop and start the app, but it will change if you rename the project or change ownership, since it has the project owner and project name in the URL.
3) The current session URL:
http://<your-domino-url>/<user>/<project>/r/notebookSession/<session_id>
This URL will change every time you start and stop the app.
Using parameters in URLs
What if you want to use a parameter in your URL? For example, what if you want your landing page to be <app url>/page.html?key1=value1
?
Currently one of the three URL options will allow URL parameters. To summarize:
1) The official app URL:http://<your-domino-url>/modelproducts/<app_id>
(URL will not ever change for an app.) Currently, you can't append a parameter to it, as it just gets ignored/thrown out.
2) The "static" internal app URL:http://<your-domino-url>/u/<user>/<project>/app
(URL will not change if you stop and start the app, but it will change if you rename the project or change ownership.) Currently, you can't append a parameter to it, as it just gets ignored/thrown out. Going to this URL in a browser immediately redirects to the next URL, your app without the Domino banner:
3) The current session URL:http://<your-domino-url>/<user>/<project>/r/notebookSession/<session_id>
(URL will change every time you start and stop the app.)
You can append parameters or paths to other pages and the app will parse them.
Example App with URL parameters
As we see above, there is a URL we can use for our App where we can append URL parameters. Great! But this URL is going to change any time the App is stopped/restarted. One way to address this is to make your initial app page a landing page, which can add your parameters before going to your main app page, or, if appropriate, prompt your app user for the parameters.
Let's look at a couple examples! For both Apps, we will use the same app.sh and app.py:
app.sh:
#!/usr/bin/env bash
python ./app.py
app.py:
import http.server
import socketserver
PORT = 8888
Handler = http.server.SimpleHTTPRequestHandler
httpd = socketserver.TCPServer(("", PORT), Handler)
print(f'serving at port {PORT}')
httpd.serve_forever()
Both Apps will also use the same main App page. This page simply greets the user by name:
appPage.html:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body onload="greetings()">
<h1>Welcome to the App!</h1>
<p id="greet"></p>
<script>
function greetings() {
let urlParams = new URLSearchParams(window.location.search);
let username = urlParams.get('name');
let timeperiod = urlParams.get('period');
if (username != null && timeperiod != null) {
document.getElementById("greet").innerHTML =
"Hello " + username + "! How are you to" + timeperiod + "?";
}
}
</script>
</body>
</html>
Example App #1
For our first example, we'll just pass coded variables as URL parameters.
Index.html:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<script>
let person = "Domino";
const d = new Date();
let theHour = d.getHours();
if(4<=theHour<=20){
var period= "day";
}
else{
period = "night";
}
location.href="appPage.html?name="+person+"&period="+period;
</script>
</body>
</html>
With this example, we can use any of the URLs to get to our main App.
The official app URL (http://<your-domino-url>/modelproducts/<app_id>
) will automatically go to appPage.html:
The "static" internal app URL )http://<your-domino-url>/u/<user>/<project>/app
) will automatically redirect to the current session URL and append the parameters:http://<your-domino-url>/<user>/<project>/r/notebookSession/<session_id>appPage.html?name=Domino&period=day
Example App #2
For our second example, we'll actually prompt the user for some input.
Index.html:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body onload="myFunction()">
<script>
function myFunction() {
const d = new Date();
let theHour = d.getHours();
if(4<=theHour<=20){
var period= "day";
}
else{
period = "night";
}
let person = prompt("Please enter your name", "");
if (person != null) {
location.href="appPage.html?name="+person+"&period="+period;
}
}
</script>
</body>
</html>
The end result of this is the same (we can use any of the URLs to get to our main App). The only difference is, this App is going to stop and prompt the user for input before moving on to our appPage.html:
Once the user adds their input - which will become a URL parameter - the official app URL (http://<your-domino-url>/modelproducts/<app_id>
) will automatically go to appPage.html:
The "static" internal app URL )http://<your-domino-url>/u/<user>/<project>/app
) will automatically redirect to the current session URL and append the parameters:http://<your-domino-url>/<user>/<project>/r/notebookSession/<session_id>appPage.html?name=Domino&period=day
Summary
The examples provided above are incredibly basic, but give you an idea of some of the ways you can utilize URL parameters for your Apps!
*Note: There is a feature request to allow users to append paths and query parameters to published apps URLs without needing alternatives such as the options described above. This request is currently tracked under DOM-26880.
Comments
0 comments
Please sign in to leave a comment.