-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ability to enable/disable CORS requests
- Loading branch information
1 parent
3e6111b
commit da7fabb
Showing
4 changed files
with
25 additions
and
5 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
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,16 +1,24 @@ | ||
from typing import List, Dict | ||
|
||
from flask import Flask | ||
from flask import Flask, Response | ||
|
||
from .common import FuncTuple | ||
from .discovery import iter_modules, iter_functions | ||
from .routes import generate_blueprint | ||
|
||
|
||
def generate_server(app_name: str = "hpi_api") -> Flask: | ||
def generate_server(app_name: str = "hpi_api", cors: bool = True) -> Flask: | ||
app: Flask = Flask(app_name) | ||
fdict: Dict[str, List[FuncTuple]] = {} | ||
for mod in iter_modules(): | ||
fdict[mod.name] = list(iter_functions(mod)) | ||
app.register_blueprint(generate_blueprint(fdict)) | ||
|
||
if cors: | ||
|
||
@app.after_request | ||
def after_request(response: Response) -> Response: | ||
response.headers["Access-Control-Allow-Origin"] = "*" | ||
return response | ||
|
||
return app |