using nginx rewrite rules with sinatra

I've been having a hard time implementing the following pattern:

1. Have a sinatra app that thinks it's hosted under / - for example

GET /input -> display a form
POST /process -> process the form

and in form.html
<form action="process" ...>

2. Expose it at host:port (currently with puma, though I'm happy to change
that if some other server makes it easier), and put it behind nginx with a
prefix, e.g. myapp, so that the actual urls are /myapp/input and
/myapp/process which rewrite to host:port/input and host:port/process

I have not been able to get the sinatra app to be entirely independent of
the myapp prefix and the puma port - I keep running into glitches where the
form posts to the wrong place, or the request hits sinatra with /myapp
still in the url so that the matching fails. Does anyone have a working
example of doing this that I can copy^take inspiration from?

martin

POST often responds with a redirect. Let's say /myapp/new -> /myapp/form -> /myapp/list. Who should make sure that /myapp is on the redirect if the redirect is coming from your sinatra app? It sounds like maybe a raw rack layer underneath your app to just deal with adding/removing this prefix might be the right approach, but I'm not sure it's the best idea.

What's your motivation for keeping the sinatra side ignorant of the prefix?

···

On Sep 24, 2019, at 13:47, Martin DeMello <martindemello@gmail.com> wrote:

2. Expose it at host:port (currently with puma, though I'm happy to change that if some other server makes it easier), and put it behind nginx with a prefix, e.g. myapp, so that the actual urls are /myapp/input and /myapp/process which rewrite to host:port/input and host:port/process

It just seems conceptually cleaner - the prefix isn't a detail of my app,
it's a detail of the way I'm hosting this particular instance of it (e.g.
if I put the app up on github, someone else might want to host it with an
entirely different prefix, or no prefix). Perhaps my best option is to have
sinatra be aware of the prefix but set it in a single place and use a
variable everywhere in the app.

martin

···

On Tue, Sep 24, 2019 at 9:21 PM Ryan Davis <ryand-ruby@zenspider.com> wrote:

> On Sep 24, 2019, at 13:47, Martin DeMello <martindemello@gmail.com> > wrote:
>
> 2. Expose it at host:port (currently with puma, though I'm happy to
change that if some other server makes it easier), and put it behind nginx
with a prefix, e.g. myapp, so that the actual urls are /myapp/input and
/myapp/process which rewrite to host:port/input and host:port/process

POST often responds with a redirect. Let's say /myapp/new -> /myapp/form
-> /myapp/list. Who should make sure that /myapp is on the redirect if the
redirect is coming from your sinatra app? It sounds like maybe a raw rack
layer underneath your app to just deal with adding/removing this prefix
might be the right approach, but I'm not sure it's the best idea.

What's your motivation for keeping the sinatra side ignorant of the prefix?