msztolcman / sendria

Sendria (formerly MailTrap) is a SMTP server designed to run in your dev/test environment, that is designed to catch any email you or your application is sending, and display it in a web interface instead of sending to real world.
MIT License
147 stars 14 forks source link

[Feature Request] Add configuration option to allow subpath for the webserver #5

Open allangood opened 3 years ago

allangood commented 3 years ago

First of all, thank you for your great work!

I am working in a way to add a configuration option (--webpath) to allow the web interface to be hosted in a subpath, like "/sendria". This is particular important for me as I would like to run it behind a reverse proxy with multiple other projects.

I am opening this request for a future PR.

Thank you.

msztolcman commented 3 years ago

Hello @allangood

Thank you for your proposal! It may take some time, however I think it's worth to add. I'll try to start working on it in a while.

sbusch commented 3 years ago

I have the same requirement. Looking forward to your PR :-)

msztolcman commented 3 years ago

Hi guys, I've already started work on it. I've already finished with hardest (from my point of view) part, I mean frontend ;) And now need to find some time for backend and polishing. Hope will find and finish soon.

msztolcman commented 3 years ago

Hi @sbusch, @allangood ,

I just pushed some initial, but mostly working version of sendria, which can work in subpath. You can install it using pip:

pip install git+https://github.com/msztolcman/sendria.git@non-root-ui-sendria

It requires new param when starting sendria, i.e.: --http-url-prefix /asd/

And slighlty modified nginx config (rewrite pragma), you can see whole config in https://github.com/msztolcman/sendria/blob/non-root-ui-sendria/addons/nginx-non-root.conf

Can you take a look is this working fine or not? I will try to test it more in few days, however other pair of eyes would be very useful :)

allangood commented 3 years ago

Hello @msztolcman ,

Thank you for your update!

I've tried to build but couldn't build the assets:

/home/sendria/.local/bin/webassets -m sendria.build_assets build
Traceback (most recent call last):
  File "/home/sendria/.local/bin/webassets", line 8, in <module>
    sys.exit(run())
  File "/home/sendria/.local/lib/python3.9/site-packages/webassets/script.py", line 578, in run
    sys.exit(main(sys.argv[1:]) or 0)
  File "/home/sendria/.local/lib/python3.9/site-packages/webassets/script.py", line 572, in main
    return GenericArgparseImplementation(env).main(argv)
  File "/home/sendria/.local/lib/python3.9/site-packages/webassets/script.py", line 557, in main
    return self.run_with_argv(argv)
  File "/home/sendria/.local/lib/python3.9/site-packages/webassets/script.py", line 549, in run_with_argv
    return self.run_with_ns(ns)
  File "/home/sendria/.local/lib/python3.9/site-packages/webassets/script.py", line 531, in run_with_ns
    env = self._setup_assets_env(ns, log)
  File "/home/sendria/.local/lib/python3.9/site-packages/webassets/script.py", line 509, in _setup_assets_env
    env = PythonLoader(ns.module).load_environment()
  File "/home/sendria/.local/lib/python3.9/site-packages/webassets/loaders.py", line 272, in __init__
    self.module = import_module(module_name)
  File "/home/sendria/.local/lib/python3.9/site-packages/webassets/importlib.py", line 36, in import_module
    __import__(name)
  File "/home/sendria/.local/lib/python3.9/site-packages/sendria/build_assets.py", line 4, in <module>
    environment = configure_assets(False, False)
  File "/home/sendria/.local/lib/python3.9/site-packages/sendria/http/core.py", line 272, in configure_assets
    assets = webassets.Environment(directory=config.STATIC_DIR, url=config.CONFIG.url_static)
AttributeError: 'NoneType' object has no attribute 'url_static'

Am I missing something?

msztolcman commented 3 years ago

Hi @allangood,

I missed some problems with running webassets manually. It's not related to this issue, will fix this later. Please run sendria with -a switch, then it should automatically create assets. This works fine on newly created vps. Also, I've updated nginx config, now it works with url's without trailing /.