Skip to content
AmmarkoV edited this page Oct 20, 2012 · 10 revisions
AmmarServer default page viewed on a browser



AmmarServer and Static Pages
For static files Ammar Server operates just like every other web server. It can use a directory ( by default public_html ) and make all the files and folders inside visible to web client requests.
 
For the classic "hello world" example , we could go and replace the index.html file content with <html><body>Hello World</body></html> and thats it.
All the incoming requests would  get served with the hello world page just as expected..


Mirroring a dynamic Wordpress site ( LAMP , PHP / MySQL ) with wget and AmmarServer
In order to clone a dynamic web-site and then serve it with AmmarServer you can use the bash script provided in the repository and called "MirrorAmmarServer.sh"
Lets say that your WordPress blog is hosted on http://ammar.gr .
STEP 1 ) Being on the parent directory of AmmarServer  issue "./MirrorAmmarServer.sh http://ammar.gr"
wget will gradually start to mirror the site into static files and create a subdirectory called ammar.gr/ where the files will be stored
STEP 2 ) Edit the file src/main.c and change  char webserver_root[MAX_FILE_PATH]="public_html/"; to char webserver_root[MAX_FILE_PATH]="ammar.gr/";
If you want you can change the DEFAULT_BINDING_PORT to another port ( you may want to set it to port 80 because the default is 8080 )
STEP 3 ) issue "./make && ./run_ammarserver" and voila your site will be availiable at http://127.0.0.1:8080 ( or any other port you choose )


 

Writing a More Dynamic Service
Stepping up the difficulty curve , lets say we want to write a dynamic hello world message which will count the times it got viewed and output them on each client request.
You can review the helloworld example here , most of the lines are comments and as you will soon figure out , what we do is create a virtual file called "index.html" and redirect all requests to it to a callback function called prepare_helloworld_content_callback. When prepare_helloworld_content_callback is executed it fills helloworld.content with a webpage and then returns. The webserver serves this result back to the client and the process continues..!

We can also query GET and POST variables rather like the PHP $_GET[] , $_POST[] and $_FILE[] arrays by using the provided functions  AmmServer_GETArg and AmmServer_POSTArg , please note that the naming conventions will change to become more practical as the project matures and this will have to happen soon in order to prevent breaking services due to interfacing changes.. $_GET["user"] is much prettier than AmmServer_GETArg(form,"user",val,256) I know.. :P

TODO : Gradually as more functionality will get implemented more examples and information will be added here.. !
For further questions and bug reports fill free to use the issues system..




 



Download AmmarServer
Download AmmarServer
Latest Snapshot

Clone this wiki locally