1

I've been working with Node.JS applications for a while now. In Node.JS it's really easy to accept Cross-origin-requests using the NPM package CORS. What I normally do is this:

const cors = require('cors'); app.use(cors());

But at now I want to do an XMLhttpRequest from my Digital Ocean server to my TransIP webhosting (just FTP). Now I get No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin /* here my website */ is therefore not allowed access.

How can I enable cross origin request for just one IP (that of Digital Ocean)? I've been looking around for a while, but didn't get wiser. And if not possible, how can I allow all other domains to be able to read JSON files on my webhosting?

Hope someone can help!

  • 1
    You could try configuring a `.htaccess` file like this: https://stackoverflow.com/questions/13421463/htaccess-access-control-allow-origin Specifying your domain instead of `*` – yuriy636 Aug 29 '17 at 11:54
  • @yuriy636 Thanks for your response! Do you mean the webhosting domain (the FPT thing I was talking about), or the IP domain from Digital Ocean? – Camille Sébastien Niessen Aug 29 '17 at 12:01
  • 1
    The Digital Ocean one (it's the same as the origin mentioned in the error, right?). Also, this works on Apache servers, I'm not sure if the hosting you mentioned uses it (I don't know Dutch). Also found this: https://enable-cors.org/server.html – yuriy636 Aug 29 '17 at 12:05

0 Answers0