Giter Club home page Giter Club logo

cherrypy-cors's People

Contributors

jaraco avatar nylki avatar tabo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cherrypy-cors's Issues

CORS and routes dispatcher

Hi,
I would like to integrate your pakage in my application.
I have a RoutesDispatcher more or less like this example.

Could you help me?
Thanks

Decorator not working

In investigating #1, I tried using the decorator, as described in the docstrings, but when I did, it didn't work. I'm not sure if it was user error or a bug in the decorator, so more investigation is needed.

Runable example

Originally reported by: Markus Bergholz (Bitbucket: markuman, GitHub: markuman)


A minimal runable example file would be very helpful. When searching for cherrypy_cors.install() on github, you get >10 different variations how people try using cherrypy_cors.

Currently I'm trying to receive a json object with @cherrypy.tools.json_in() from a HTML file whitch isn't served by cherrypy

#!html

<html>
<head>
<script>
function makeRequest()
{
    var xmlhttp = new XMLHttpRequest();   // new HttpRequest instance 
    xmlhttp.open("POST", "http://localhost:8080");
    xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
    xmlhttp.send(JSON.stringify({user:"John Rambo", time:"2pm"}));

}
</script>
</head>
<body>
<form name="frm1" id="yourTextBox" onsubmit="makeRequest()">
<input type="submit" value="Submit">
</form>
</body>
</html>

I hope you can help me.


Support origin whitelisting

Feature Request

Add support to expose() and preflight() for enabling CORS for specific domains.

Sample Usage

Decorator

DOMAIN_REGEX = re.compile('^sd[1-9]\.example\.org$')
ORIGINS = ['a.example.com', 'b.example.net', DOMAIN_REGEX]

class MyResource(object):

    @cherrypy_cors.tools.preflight(
        allowed_methods=['GET', 'DELETE', 'PUT'], origins=ORIGINS)
    def OPTIONS(self):
        self._delete()

    @cherrypy_cors.tools.expose(origins=ORIGINS)
    def DELETE(self):
        self._delete()

Configuration

            config = {
                '/resources': {
                    'cors.expose.on': True,
                    'cors.expose.origins': ['my.example.com', 'www.example.net'],
                    'cors.preflight.origins': ['my.example.com', 'www.example.net'],
                }
            }

Preferably, expose() and preflight() could read the origins parameter from a common config setting (I don't know whether cherrypy tools support that).

            config = {
                '/resources': {
                    'cors.expose.on': True,
                    'cors.origins': ['my.example.com', 'www.example.net'],
                }
            }

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.