GithubHelp home page GithubHelp logo

Comments (8)

Rob--W avatar Rob--W commented on May 18, 2024

How are you using CORS Anywhere?

from cors-anywhere.

titanco avatar titanco commented on May 18, 2024

I'm using CORS Anywhere for a flash video player, and flash player request 'crossdomain.xml' on root of domain.
I try put crossdomain.xml on my serve but when i access via http://host:port/crossdomain.xml it show 404 error.
So, can i do that with CORS Anywhere ? Where i can put 'crossdomain.xml' file ?

from cors-anywhere.

titanco avatar titanco commented on May 18, 2024

I just hack to your code and add:
if (location.host === 'crossdomain.xml') { res.writeHead(200, {'Content-Type': 'application/xml'}); var xmll = ''; res.end(xmll); return; }
Run ok, but this is not legit, can you have any idea?

from cors-anywhere.

Rob--W avatar Rob--W commented on May 18, 2024

You can simply create a CORS Anywhere server without listening on a port, and then create another HTTP server that handles requests to /crossdomain.xml and otherwise forwards the request to CORS Anywhere.

For example:

var cors_proxy = require('cors-anywhere').createServer({
  requireHeader: ['origin', 'x-requested-with'],
  removeHeaders: [
    'cookie',
    'cookie2',
  ],
  // See README.md for other options
});

var fs = require('fs');
require('http').createServer(function(req, res) {
  if (req.url === '/crossdomain.xml') {
    fs.createReadStream('crossdomain.xml').pipe(res);
    return;
  }
  // Let the server handle it
  cors_proxy.emit('request', req, res);
}).listen(8080); // Listen on port 8080.

Reading the file again on every acces of crossdomain.xml is not quite efficient, I recommend reading the caching the contents of the file if possible.

Also note that the above code handles http://example.com:8080/crossdomain.xml but not http://example.com:8080/crossdomain.xml?some=value because it looks for an exact match. If you want to allow any prefix to be handled, use req.url.startsWith('/crossdomain.xml') instead (modern Node.js versions only) or req.url.lastIndexOf('/crossdomain.xml', 0) === 0 (any Node.js version).

from cors-anywhere.

titanco avatar titanco commented on May 18, 2024

Thank you so much for your time !
Closing ...

from cors-anywhere.

titanco avatar titanco commented on May 18, 2024

Hello,
I try your code, but it show error:
TypeError: cors_proxy.emit is not a function

from cors-anywhere.

Rob--W avatar Rob--W commented on May 18, 2024

I've edited the snippet, and changed

var cors_proxy = require('cors-anywhere');
cors_proxy.createServer(...);

to

var cors_proxy = require('cors-anywhere').createServer(...);

from cors-anywhere.

titanco avatar titanco commented on May 18, 2024

Its woking, thank you.

from cors-anywhere.

Related Issues (20)

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.