Server documentation
Contents
Make a new site
First, it's a good idea to make sure the example site works.
Do this by compiling and running the server with the example configuration.
./build.sh conf=example
./server
Now try to visit http://localhost:8080/ in a web browser.
If it works, next step is to either make a new site under the example configuration, or make a new configuration.
This is how to make a new configuration and add a new static site to it:
- Make a new directory under the conf directory. You can call it "default" if you want to make this the configuration that is built by default.
- Enter the newly created directory and make three files (look at the example conf for help):
- build.sh - This script should build your site and create an executable with the same name as your site in the directory of your site.
- respond.c - This file should contain a function called `respond` that will run directly on the web server (not in your site executable). It needs to send the HTTP response to the socket of the client. This is usually done by executing your site program by calling the `respond_site` function and then returning true (true means that we responded to the request).
- servers.c - Needs to define an array of `struct ChildServer` named `children`. This file tells the supervisor what servers it should start and keep alive.
- Add a new directory in the project root, with the name of your site, e.g. "mysite".
- In your site directory, add mysite.c (the file compiled by your build.sh). In this file you need to:
- `#define SITE_IS_HTTP 1` if you want your site to work with the HTTP server. It is also possible to make sites that use other interfaces.
- `#include "../src/site.c"`. Must be done below the preprocessor definitions.
- Define the function `site_respond`. All this function needs to do is to write the HTTP response to standard out. For a simple static site, this function can just call `respond_file` where the second argument should be the name of a directory under your site directory where you will store the files you want to serve.
- Add the directory under your site directory where you will put the files to serve. This directory is called "files" in the example site.
Files
Directories
File | Description |
conf/ | Environment and build configurations. Determines what sites are built and executed when running the server. Specified to the build script, e.g. `./build.sh conf=example`. |
doc/ | Server documentation. Available either by opening doc/index.html directly or by running the example site and following the link on the example front page. |
example/ | Example website. Look here to see how to make your own site. This site uses static files, dynamic pages and database. |
src/ | Server source code. Entry points:
Source file | Output file | Description |
src/cinj.c | ./cinj | C-injection compiler; code injection into pages. |
src/dbserver.c | ./example/exampledb.so (site specific) | Database server. Included and compiled by each site as library with entry point `server_main`. |
src/dbspec.c | ./dbspec | Database definition language. |
src/master.c | ./server | Supervisor. Run this to run the server. |
src/site.c | ./example/example (site specific) | Entry point for websites. Included and compiled by each site. |
src/test.c | ./test | Automatic tests of server functions. |
src/webserver.c | ./webserver.so | The HTTP web server. Compiled as library with entry point `server_main`. |
|
All files
Size | File |
1482 | build.sh |
156 | conf/example/build.sh |
362 | conf/example/respond.c |
463 | conf/example/servers.c |
6454 | doc/index.html |
26 | example/dbconfig |
2510 | example/example.c |
80 | example/example.dbspec |
1607 | example/exampledb.c |
9 | example/files/doc |
282 | example/files/index.html |
228 | example/generate.sh |
383 | example/pages/dynamic.html |
16168 | src/cinj.c |
19824 | src/common.c |
2688 | src/config.c |
1050 | src/dbclient.c |
6350 | src/dbcommon.c |
44222 | src/dbfile.c |
5397 | src/dbserver.c |
43731 | src/dbspec.c |
908 | src/hamt.c |
2101 | src/http.c |
4587 | src/master.c |
342 | src/master.h |
3563 | src/page.c |
3900 | src/response.c |
2582 | src/site-http.c |
15336 | src/site.c |
5533 | src/test.c |
9385 | src/webserver.c |
Licence
There is no licence yet because this software has not yet been published.
This is just a preview version.