A relatively simple multi-platform C HTTP server.
To build and install mhserv
you need to have mh
and it's build dependencies
installed.
git clone https://github.com/mihail-8480/mhserv
cd mhserv
cmake .
cmake --build .
cmake --install .
You might need root permissions for cmake --install .
because it tries to copy files into /usr/local/lib
by
default.
You can build and install it using mhpkg
.
mhpkg install mh
mhpkg install mhserv
To make a simple test if it's built and installed correctly you can run mhserv
with libexample.so
:
cd bin
mhserv ./libexample.so
You need to replace the .so
extension with .dll
if you are on Windows or .dylib
if you are on Mac.
Then go to the default URL, if a webpage is displayed - it works!
If you have your own handler library you can load it in the same way.
Name | Description | Default |
---|---|---|
MH_LIB_FUNCTION |
The function that handles the HTTP requests. | mh_http_handle |
MH_PORT |
The port that the HTTP server is hosted at. | 8080 |
MH_IP |
The IP that the HTTP server is hosted at. | 127.0.0.1 |
MH_LIB_INIT |
A function that gets executed before the listener starts. | mh_lib_init |
Create a new dynamic library / module that uses libmh.so
and declares a function that looks like this:
#include <mh_http_handler.h>
void mh_http_handle(mh_http_request_t *request) {
// your code here
}
You also need to add libmh.so
to the library's CMakeLists.txt
:
target_link_libraries(mylibrary PRIVATE mh)
See example.c
for reference.