Setup a Flask server
WayScript allows you to configure your Lair to host a running microservice in minutes. Follow this guide to setup a simple Flask app in your Lair.
Use the boilerplate code below to create a
app.pyfile in your Lair’s root directory. Or if you have an existing Flask project, copy or clone your project files into your Lair’s directory. See File system for more details on how to manipulate files in your workspace file system.
from flask import Flask
app = Flask(__name__)
return 'Hello World'
if __name__ == '__main__':
requirements.txtfile in your Lair’s root directory and specify the
flaskpackage. You can install the
pipin your Lair Terminal. You can also specify any additional dependencies your app requires. See Hosted environments for more details.
pip install flask
pip freeze > requirements.txt
Add flask to your requirements.txt file
Open your Lair’s
.triggersfile and add a new
deploytrigger. Create a name for your trigger and input the following run command and port number
8080(or modified command and port number based on your app requirements). See Triggers for more details.
flask run --port 8080 --host 0.0.0.0
Example Flask Trigger Setup
Press “Test” to execute the run command and start your web server process (see Processes for more details). Navigate to the
*.wayscript.cloudendpoint generated to see your Flask app in action!
FLASK_ENV=developmentto enable hot reload of your server process when modifying your app’s files.
Once you have finished testing, press “Deploy” to create a production environment for your Flask app. Select
<Lair_name>.prodin the Lair selector menu and view the
on deploytrigger to access your app’s production endpoint. See Hosted environments for more details.
By default, your Lair's endpoints are protected against unauthenticated requests. See Endpoints on how to public expose your endpoints or authenticate using your application key.