Giter VIP home page Giter VIP logo

Comments (6)

di avatar di commented on July 28, 2024

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.

di avatar di commented on July 28, 2024

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.

martindufort avatar martindufort commented on July 28, 2024

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.

di avatar di commented on July 28, 2024

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.

martindufort avatar martindufort commented on July 28, 2024

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.

av1m avatar av1m commented on July 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.