valum-framework / valum

Web micro-framework written in Vala
https://valum-framework.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
226 stars 23 forks source link

Configurable VSGI backend #164

Closed Bob131 closed 8 years ago

Bob131 commented 8 years ago

Most frameworks I've used in the past allow a program to be run in both HTTP and CGI mode without any changes to the codebase. I understand that currently it should be just a one-line change to go from eg VSGI.SCGI to VSGI.HTTP, but ideally this could be a CLI option to minimise the hassle of maintaining production-specific patchsets.

arteymix commented 8 years ago

This is actually covered by #130

There would be a vsgi utility able to load both a server and an application and serve the latter with the former. It's similar to gunicorn.

vsgi --server=http app:app -- --port=3003

It will eventually support:

However, it might be more convenient to expose the loader into application code so that one could load a server dynamically instead. In short, rather than passing arguments to vsgi, they would be passed directly to the code.

using VSGI.Loader;

var server = new ServerModule ("http"); // you can inject the string you want here

if (server_module.load ()) {
    var server = Object.new (server_module.server_type, "application-id": "org.example.valum.Loadable") as Server;
    server.set_application (app.handle);
    server.run ();
} else {
    error (Module.error ());
}

There would probably be a nicer API though.

arteymix commented 8 years ago

I already merged support for dynamically loadable implementation, so plugging in CGI or HTTP backend is just a matter of calling Server.@new with the appropriate argument.