This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from machsix/main
Add Blueprint to handle static files, add "url_prefix" in config.json
- Loading branch information
Showing
8 changed files
with
76 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ | |
"host": "0.0.0.0", | ||
"port": 1338, | ||
"debug": false | ||
} | ||
}, | ||
"url_prefix": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,39 @@ | ||
from server.app import app | ||
from server.bp import bp | ||
from server.website import Website | ||
from server.backend import Backend_Api | ||
from json import load | ||
|
||
from flask import Flask | ||
|
||
if __name__ == '__main__': | ||
|
||
# Load configuration from config.json | ||
config = load(open('config.json', 'r')) | ||
site_config = config['site_config'] | ||
url_prefix = config.pop('url_prefix') | ||
|
||
# Set up the website routes | ||
site = Website(app) | ||
site = Website(bp, url_prefix) | ||
for route in site.routes: | ||
app.add_url_rule( | ||
bp.add_url_rule( | ||
route, | ||
view_func=site.routes[route]['function'], | ||
methods=site.routes[route]['methods'], | ||
) | ||
|
||
# Set up the backend API routes | ||
backend_api = Backend_Api(app, config) | ||
backend_api = Backend_Api(bp, config) | ||
for route in backend_api.routes: | ||
app.add_url_rule( | ||
bp.add_url_rule( | ||
route, | ||
view_func=backend_api.routes[route]['function'], | ||
methods=backend_api.routes[route]['methods'], | ||
) | ||
|
||
# Create the app and register the blueprint | ||
app = Flask(__name__) | ||
app.register_blueprint(bp, url_prefix=url_prefix) | ||
|
||
# Run the Flask server | ||
print(f"Running on port {site_config['port']}") | ||
print(f"Running on {site_config['port']}{url_prefix}") | ||
app.run(**site_config) | ||
print(f"Closing port {site_config['port']}") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from flask import Blueprint | ||
|
||
bp = Blueprint('bp', __name__, | ||
template_folder='./../client/html', | ||
static_folder='./../client', | ||
static_url_path='assets') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters