The following guide will set up your Domino project more as a proper website powered by Flask. This isn’t difficult; you just need to make sure all the folders and files are in place to ensure the app runs correctly.
First, you’ll need to create the app structure. The following is what we’ll end up with and will discuss each area in turn.
Note that /mnt
is your Files directory on Domino.
Also, the following names matter: app.sh
, init.py
, /static
, /templates
.
Besides those, everything can be customized to your liking in this topic.
/mnt |-- ... |-- app.sh |-- run.py |-- /flask_app |-- __init__.py |-- views.py |-- /static |-- /templates
Create the folders
In the Files section of Domino make a new folder called flask_app
.
This will be a Python package that will contain the web app.
In the flask_app folder put two other folders, one called static
the other templates
.
In the static
folder you put your static files and in the templates
folder you put your template files.
The static and templates folders will be recognized by Flask to know from where to fetch the appropriate files.
It’s possible to change which folder is noticed as the static folder, but common practice is to just leave it as
static
.
Create the files
Create an init.py
file in the flask_app folder.
This file will make flask_app a Python package.
In that file put the following:
from flask import Flask
class ReverseProxied(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
script_name = environ.get('HTTP_X_SCRIPT_NAME', '')
if script_name:
environ['SCRIPT_NAME'] = script_name
path_info = environ['PATH_INFO']
if path_info.startswith(script_name):
environ['PATH_INFO'] = path_info[len(script_name):]
# Setting wsgi.url_scheme from Headers set by proxy before app
scheme = environ.get('HTTP_X_SCHEME', 'https')
if scheme:
environ['wsgi.url_scheme'] = scheme
# Setting HTTP_HOST from Headers set by proxy before app
remote_host = environ.get('HTTP_X_FORWARDED_HOST', '')
remote_port = environ.get('HTTP_X_FORWARDED_PORT', '')
if remote_host and remote_port:
environ['HTTP_HOST'] = f'{remote_host}:{remote_port}'
return self.app(environ, start_response)
app = Flask(__name__)
app.wsgi_app = ReverseProxied(app.wsgi_app)
Back in your Files section of Domino create a new file called run.py
.
In run.py
add the following:
from flask_app import app
from flask_app import views
if __name__ == '__main__':
app.run()
Change your app.sh
file in the Files section of Domino to:
#!/usr/bin/env bash
export FLASK_APP=run.py
export FLASK_DEBUG=1
python -m flask run --host=0.0.0.0 --port=8888
The app.sh
file
When you publish an app, Domino looks for an app.sh
file in your project to find the launch instructions. Aside from the app.sh
file, Domino’s app development process mirrors standard development so your apps are portable and can be deployed elsewhere. Just include your app’s files in your Domino project.
When Domino launches your app, it runs the app.sh
file within the container that contains your project files. The app.sh
file must contain the commands to start the web hosting process.
Note
|
Domino requires this configuration for app service: 0.0.0.0 on port 8888 .
If your hosting network uses a different default, specify that default in your app.sh file or some alternate configuration.
|
Customization
Now we’re going to add a views.py
file.
This file is where you place all your app logic and should be created in the flask_app directory.
We’ll make a very simple app that just returns “Hello World!”
Add the following to views.py
:
from flask_app import app
@app.route('/')
def index():
return "Hello World!"
If you have a template in the templates folder, you would add:
from flask import render_template
from flask_app import app
@app.route('/')
def index():
return render_template('hello.html')
-
Click Deployments > App from the project sidebar.
-
Give your app an informative title and description, and set permissions to Anyone can access. This allows anyone with a network connection to your Domino deployment to access the app if they have the URL.
TipLeave Show in Launchpad selected to make your app easily discoverable. You can always change this later. -
Click Publish.
-
After the App status says "Running", click View App to load your app.
Now, you can set the permissions on your app to Anyone can access to share it with colleagues who have access to your Domino instance. You can try this out yourself by opening a private or incognito browser, or logging out of Domino, and navigating to the Deployments > App > Copy App Link.
To browse more apps, click Deploy > Apps in the top navigation menu.