Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow CORS with Middleware #532

Closed
rfschubert opened this issue Jan 21, 2019 · 2 comments
Closed

Allow CORS with Middleware #532

rfschubert opened this issue Jan 21, 2019 · 2 comments
Labels
enhancement New feature or request medium difficulty Not too difficult but may be harder for newer collaborators next minor Issue scheduled for the next minor release

Comments

@rfschubert
Copy link
Contributor

rfschubert commented Jan 21, 2019

PR this Middleware to core of Masonite

""" CORS Middleware """

from masonite.request import Request


class CORSMiddleware:
    """CORS Middleware
    """

    CORS = {
            "Access-Control-Allow-Origin": "*"
        }

    def __init__(self, request: Request):
        """Inject Any Dependencies From The Service Container

        Arguments:
            Request {masonite.request.Request} -- The Masonite request object
        """

        self.request = request

    def after(self):
        """Run This Middleware After The Route Executes
        """
        '''"
                |--------------------------------------------------------------------------
                | Create Dictionary of CORS headers
                |--------------------------------------------------------------------------
                |
                | Appends CORS headers to HTTP response
                |
                | Ex. cors = {"Access-Control-Allow-Origin": "*",
                |             "Access-Control-Allow-Headers": "Content-Type",
                |             "Access-Control-Allow-Methods": "DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT"}
                |
                ''""
        for key, value in self.CORS.items():
            self.request.header(key, value, http_prefix=None)

Also create some tests

@vaibhavmule vaibhavmule changed the title Allor CORS with Middleware Allow CORS with Middleware Jan 21, 2019
@josephmancuso josephmancuso added enhancement New feature or request next minor Issue scheduled for the next minor release medium difficulty Not too difficult but may be harder for newer collaborators labels Jan 21, 2019
@vaibhavmule
Copy link
Contributor

vaibhavmule commented Jan 22, 2019

Note: Referencing #320 to check conversation around adding CORS middleware in past.

@rfschubert
Copy link
Contributor Author

Note: Referencing #547 a PR with the conclusion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request medium difficulty Not too difficult but may be harder for newer collaborators next minor Issue scheduled for the next minor release
Projects
None yet
Development

No branches or pull requests

3 participants