paypal / react-engine

a composite render engine for universal (isomorphic) express apps to render both plain react views and react-router views
Apache License 2.0
1.45k stars 130 forks source link

(Bug) React-engine error when req.url store dot character. #139

Open ghost opened 8 years ago

ghost commented 8 years ago

When I do a request that store a dot character, e.x: http://localhost/profile/abc.xyz. Then, nodejs will notify 'error: uncaughtException: Cannot find module 'xyz'. I know it occur due to the ReactEngineView function in the react-engine/lib/expressView.js, in depth the ReactEngineView function will call the View function at express/lib/view.js. The View function as the following code:

function View(name, options) {
  var opts = options || {};

  this.defaultEngine = opts.defaultEngine;
  this.ext = extname(name); // <--------- Error here
  this.name = name;
  this.root = opts.root;

  if (!this.ext && !this.defaultEngine) {
    throw new Error('No default engine was specified and no extension was provided.');
  }

  var fileName = name;

  if (!this.ext) {
    // get extension from default engine name
    this.ext = this.defaultEngine[0] !== '.'
      ? '.' + this.defaultEngine
      : this.defaultEngine;

    fileName += this.ext;
  }
  console.log(this.ext);
  if (!opts.engines[this.ext]) {
    // load engine
    opts.engines[this.ext] = require(this.ext.substr(1)).__express;
  }

  // store loaded engine
  this.engine = opts.engines[this.ext];

  // lookup path
  this.path = this.lookup(fileName);
}
ghost commented 8 years ago

I have created a PR at https://github.com/paypal/react-engine/pull/140