Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request View global option ignore extname #2708

Open
reggi opened this issue Jul 16, 2015 · 12 comments
Open

Feature request View global option ignore extname #2708

reggi opened this issue Jul 16, 2015 · 12 comments
Assignees
Milestone

Comments

@reggi
Copy link

reggi commented Jul 16, 2015

In react-engine you set the view engine via a global app.set variable.

app.set('view engine', 'js')

My request is for another global view option

app.set('view ignore extname', true)

Here's why:

In react engine you pass the current page url to res.render

app.get("/", function(req, res){
  return res.render(req.url, data)
})

When that url has a period it is picked up by a rendering engine the as an extname. So for the url /hello?url=google.com you get an error because it's looking for the module com.

You can enable periods in react-engine simply by commenting out this line. I'm putting in a pull request to copy the whole View with this line commented but it would be great if express supported it.

Is there a way to do this already?

@dougwilson
Copy link
Contributor

Hi @reggi ! I'm not sure what feature you are requesting. Can you add more details/specificity?

@reggi
Copy link
Author

reggi commented Jul 16, 2015

Sorry @dougwilson I pressed enter too quickly and it posted with no content, updated!

@dougwilson
Copy link
Contributor

Unfortunately view names are specifically file system based names. This means you cannot pass in URLs. At best, you can always do res.render(url.parse(req.url).pathname, data) to strip off the query string.

@dougwilson
Copy link
Contributor

Actually, something we could do is provide something better than a "default" engine, or even expand the default engine in Express 5.0 to include files that have an extension but no mapping.

@reggi
Copy link
Author

reggi commented Jul 16, 2015

@dougwilson in the case of react-engine it allows (encourages you) you to pass in req.url. They have methods of rending a specific react view based on the entire url.

Here's a log from this at line [75 of view.js]

Visiting route with this.ext uncommented. (Error Cannot find module 'world')

{ useRouter: true,
  defaultEngine: 'js',
  ext: '.world',
  name: '/hello.world',
  root: '/Users/thomas/Desktop/node-app/public/views' }

Visiting route with this.ext commented. (Works)

{ useRouter: true,
  defaultEngine: 'js',
  name: '/hello.world',
  root: '/Users/thomas/Desktop/node-app/public/views',
  ext: '.js' }

@dougwilson
Copy link
Contributor

Yes, they can recommend stuff all they want, but it doesn't change the fact that our current views only work with file system names. Frankly, their documentation is wrong/incomplete. You need to use res.render(url.parse(req.url).pathname, data) to strip off the query string.

@reggi
Copy link
Author

reggi commented Jul 16, 2015

@dougwilson The example above is the url /hello.world this error would occur with the period in any part of the url even /index.html, so it's not specific to periods in the query string.

@dougwilson
Copy link
Contributor

@dougwilson The example above is the url /hello.world this error would occur with the period in any part of the url even /index.html.

I've already provided the solution we will implement at #2708 (comment) which would work for the use-case you presented here.

@reggi
Copy link
Author

reggi commented Jul 16, 2015

Thanks a bunch @dougwilson! Excited to see this feature in Express 5.

@syzer
Copy link

syzer commented Nov 26, 2015

👍

@hacksparrow
Copy link
Member

@reggi if there's no route defined for /hello.world, wouldn't it 404? Can you show a simple example of reproducing the extension error?

@dougwilson I am taking a look at this. Can you explain "include files that have an extension but no mapping" with an example?

@czaarek99
Copy link
Contributor

@dougwilson I'd also be interested in actually implementing this but as it stands it's not clear what is actually requested as @hacksparrow explained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants