mjackson / mach

HTTP for JavaScript
810 stars 41 forks source link

map(http://example.com/mountpoint) not working as expected #54

Closed appsforartists closed 9 years ago

appsforartists commented 9 years ago

I have an app that's packaged up into a mach stack. I'd like to test variations on it, such that:

After seeing that this appears to be supported in the docs, I tried each of these techniques:

var mapper = mach.mapper();

mapper.map(
  "http://example1.local",
  stack1
)

mapper.map(
  "http://example2.local",
  stack2
)

mapper.map(
  "http://example3.local",
  stack3
)

mapper.map(
  "http://example1.local/b",
  stack1b
)

mapper.map(
  "http://example2.local/b",
  stack2b
)

mapper.map(
  "http://example3.local/b",
  stack3b
)

mach.server(
  mapper,
  8080
)

var mapper = mach.mapper();

stack1.serve(
  "*",
  // …
)

stack1.map(
  "/b",
  stack1b
)

mapper.map(
  "http://example1.local",
  stack1
)

stack2.serve(
  "*",
  // …
)

stack2.map(
  "/b",
  stack2b
)

mapper.map(
  "http://example2.local",
  stack2
)

stack3.serve(
  "*",
  // …
)

stack3.map(
  "/b",
  stack3b
)

mapper.map(
  "http://example3.local",
  stack3
)

mach.server(
  mapper,
  8080
)

(This one was kind of a mistake. The serve call is in a different file, so I didn't realize I had placed a serve call higher in the stack that the map call.)


var mapper = mach.mapper();

stack1.map(
  "/b",
  stack1b
)

stack1.serve(
  "*",
  // …
)

mapper.map(
  "http://example1.local",
  stack1
)

stack2.map(
  "/b",
  stack2b
)

stack2.serve(
  "*",
  // …
)

mapper.map(
  "http://example2.local",
  stack2
)

stack3.map(
  "/b",
  stack3b
)

stack3.serve(
  "*",
  // …
)

mapper.map(
  "http://example3.local",
  stack3
)

mach.server(
  mapper,
  8080
)

Each time, I received an error like this:

Warning: No route matches path "/b". Make sure you have <Route path="/b"> somewhere in your routes

which tells me that the variant isn't being mapped as requested.

appsforartists commented 9 years ago

:facepalm:

After trying method #4 (making a new stack for each and mounting each variant into it), I've realized the problem. ReactRouter doesn't know about the mapping, so it tries to run on the client side and gets confused by the paths.

Grrrr....

Sorry for the noise.