Comments (6)
Hi @martindufort, thanks for filing an issue.
If I understand correctly, you have multiple individual functions and you'd like to be able to serve them all simultaneously. You do not have a single function that you're trying to serve multiple endpoints from, is that correct?
If so, you're correct that the Functions Framework doesn't currently support that, but I think it would probably be a reasonable feature request. How would you imagine invoking the framework with multiple targets?
from functions-framework-python.
Also, a follow-up question: are these all the same function type, or are they a mix of HTTP and Background functions?
from functions-framework-python.
Hi @di, thanks for the quick reply.
A little bit of background: We have a server component to our solution which is being managed by the GCloud API Gateway connected to a number of cloud functions (http-triggered)
Within our Openapi description document, each route (URL Path) is directed to a specific Cloud Function.
paths:
/account/make:
post:
operationId: makeAccount
x-google-backend:
address: https://us-central1-xxxx.cloudfunctions.net/makeAccount
When we deploy them, they are all accessible from the same host but with a specific URL path.
So I would like to have a similar configuration for local testing where we would serve all these functions simultaneously on the same host:port combination.
Then we will be able to mimic the API Gateway functionality and test those locally.
For the configuration, I was thinking we could supply a .yaml file that would describe the mapping between the URL-Path and the (source file/target function) locally.
Let me know if this is clear enough.
from functions-framework-python.
Thanks for the replies @martindufort! Makes sense.
This is probably not something the Function Frameworks will support directly, however I created #99 to show an example of using skaffold, minikube, Cloud Buildpacks, and the Function Framework to run multiple functions on the same host and route based on some path.
I think this should satisfy your use case, please take a look and let me know!
from functions-framework-python.
Hi @di, I had a look at #99 and it looks good.
However this is involving too many external dependencies for us. And we want to manage them at a minimum.
We might try to fork and change some of the functionality to provide a lighter mechanism for our needs.
Will report back if we go that route.
Thanks for your reply.
from functions-framework-python.
I think you can bypass using this method, an example :
# main.py
from flask import Flask, request
app = Flask(__name__)
@app.route("/", methods=["GET"])
def main():
return "<h1>Hello World</h1>", 200
@app.route("/user/<string:id>", methods=["POST", "GET"])
def user(id):
if request.is_json:
return {"id": id, **request.json}, 200
return {"id": id}, 200
def entrypoint(request):
# Create a new app context for the app
internal_ctx = app.test_request_context(
path=request.full_path, method=request.method
)
# Copy the request headers to the app context
internal_ctx.request = request
# Activate the context
internal_ctx.push()
# Dispatch the request to the internal app and get the result
return_value = app.full_dispatch_request()
# Offload the context
internal_ctx.pop()
# Return the result of the internal app routing and processing
return return_value
Run this script with the following command :
functions_framework --target entrypoint
You can also see this example with blueprints https://github.com/av1m/functions-multiple-endpoints.git
from functions-framework-python.
Related Issues (20)
- Code behaves differently with debug flag HOT 2
- The framework default Gunicorn configs do not make sense for Gen2 environments HOT 5
- remove requirement for requirements.txt when specifying dependencies for deploying to functions: support poetry HOT 3
- Exception has occurred: SystemExit 3 HOT 6
- Symbolic linking within the Source Directory to include shared local directories.
- Firebase Functions Support HOT 1
- Possibility for multiple target/signature-type pairs?
- Gunicorn 21 is out HOT 3
- Flask Celery worker raise RuntimeError(unbound_message) from None RuntimeError: Working outside of request context. HOT 2
- Add Flask 3 support HOT 2
- README.md - Flask "Request" object hyperlink is broken HOT 2
- Native support for Pydantic models for function_framework.typed
- Document functions_framework.typed
- Support for postponed annnotations
- Improve developer experience for uncaught exceptions on GCP HOT 1
- PyPi development status alpha and other classifiers HOT 1
- functions-framework and tuning gunicorn HOT 1
- enhance framework to support pull subscriptions in addition to push subscriptions with pubsub
- Memory leaks? HOT 2
- ModuleNotFoundError: No module named 'urllib3.packages.six.moves'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from functions-framework-python.