javascript - Execute route if only the local Angular App calls it true the controller -
i have few api routes app (controller.js
) should have access to. there way use ip address (possibly insecure because of spoofing) create restriction of uses part of api?
server size (server.js)
app.get("/api/specs",function(req,res){ // app should have access it, not external entities res.json({used:getused()}); });
client side (controller.js)
$http.get('/api/specs').success(function(specs,code){ console.log(specs); });
by default browser doesn't allow make cross-site http requests because subject of same origin policy.
note:
in particular, meant web application using xmlhttprequest make http requests domain loaded from, , not other domains.
which means in case js in same domain of api can have access them.
what if want extend use of api other domains?
well in case have setup in backend api access-control-allow-origin
header.
some eg:
// cross-site http requests http://sitea.com access-control-allow-origin: http://sitea.com // cross-site http requests access-control-allow-origin: *
if want debug behaviour can open firebug , check in networks headers of requests.
references:
https://developer.mozilla.org/en-us/docs/web/http/access_control_cors
https://developer.mozilla.org/en-us/docs/web/security/same-origin_policy
Comments
Post a Comment