AngularJS not detecting Access-Control-Allow-Origin header?

后端 未结 9 1269
眼角桃花
眼角桃花 2020-11-28 11:20

I am running an angular app on a local virtualhost (http://foo.app:8000). It is making a request to another local VirtualHost (http://bar.app:8000) using $http.post

9条回答
  •  自闭症患者
    2020-11-28 11:45

    I was sending requests from angularjs using $http service to bottle running on http://localhost:8090/ and I had to apply CORS otherwise I got request errors like "No 'Access-Control-Allow-Origin' header is present on the requested resource"

    from bottle import hook, route, run, request, abort, response
    
    #https://github.com/defnull/bottle/blob/master/docs/recipes.rst#using-the-hooks-plugin
    
    @hook('after_request')
    def enable_cors():
        response.headers['Access-Control-Allow-Origin'] = '*'
        response.headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS, PUT'
        response.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept'
    

提交回复
热议问题