0

I'm using the following get:

app.get("/:project/*", auth, function (req, res) {

Then parsing against a config file to load a directory dynamically:

var path = req.params[0] ? req.params[0] : "index.html";
res.sendfile( path, { root: "./builds/" + config[req.params.project].dir + "/dist/" } );

Which works great, only problem is that it requires my urls to end with a "/" if I'm going to the default (index.html). For example, I have to use http://server.com/some_project/ and if the trailing slash isn't there it throws a Cannot GET /some_project error. Curious if there's a way around this?

Olimpiu POP
  • 5,001
  • 4
  • 34
  • 49
Fluidbyte
  • 5,162
  • 9
  • 47
  • 76

1 Answers1

0
app.get("/:project/?*", ...)

Add the question mark. That should allow you to do with or without the trailing slash.

nowk
  • 32,822
  • 2
  • 35
  • 40
  • Tried adding the `?` and now it doesn't seem to load anything on the route, just hangs there until it times out. – Fluidbyte Nov 26 '13 at 15:07
  • Can you share some info? Url you tried and maybe the stack trace? – nowk Nov 26 '13 at 19:39
  • It's not even hitting the `app.get("/:project/?*", ...)`. I console log'd right inside and nothing. The URL is on a private server but it's just as stated in the original question, nothing special. – Fluidbyte Nov 26 '13 at 22:53
  • Looks like I may be best implementing a forced trailing slash, something like (the reverse of) this: http://stackoverflow.com/a/13443359/957500 with conditions to handle files in the req.params – Fluidbyte Nov 26 '13 at 22:57