2022-08-05 22:05:10 +00:00
| [Home ](/trick ) → [Documentation Home ](../Documentation-Home ) → Web Server |
|------------------------------------------------------------------|
2021-08-18 18:15:10 +00:00
# Adding a Web Server to Your Sim
2019-11-19 20:21:07 +00:00
2022-08-15 19:16:29 +00:00
If Trick is [configured with Civetweb ](Configure-Civetweb.md ),
2021-10-27 19:02:01 +00:00
adding a web server to your simulation simply requires including the CivetServer sim module into your **S_define** file:
2019-11-19 20:21:07 +00:00
2021-08-18 18:15:10 +00:00
```
#include "sim_objects/CivetServer.sm"
2019-11-19 20:21:07 +00:00
```
2021-08-18 18:15:10 +00:00
## Configuration of the Web Server
2019-11-19 20:21:07 +00:00
2024-05-23 15:13:50 +00:00
The following (`input.py`) parameters are available to configure your web server:
|Parameter Name | Default Value | Description |
|---------------------------|---------------------------|-------------------------------------------------------------------|
|web.server.enable | `False` |Must be explicitly enabled |
|web.server.port | `8888` |Web servers “listen” port |
|web.server.document_root | `"www"` |Web servers document root |
|web.server.debug | `False` |Print Client/Server Communication. |
|web.server.ssl_enable | `False` |Encrypt traffic. Uses https instead of http. |
|web.server.path_to_ssl_cert|`"~/.ssl/server.pem"` |Path to your certificate. This is only used if `ssl_enable = True` |
|web.server.error_log_file |`"civet_server_error.log"` |CivetWeb error log file. |
2019-11-19 20:21:07 +00:00
2021-08-18 18:15:10 +00:00
For your web server to be active, you must at least specify the following :
2019-11-19 20:21:07 +00:00
```python
2021-08-18 18:15:10 +00:00
web.server.enable = True
2019-11-19 20:21:07 +00:00
```
2024-05-23 15:13:50 +00:00
To have your web server listen on port `8890` , rather than `8888` , you would specify:
2019-11-19 20:21:07 +00:00
```python
2024-05-23 15:13:50 +00:00
web.server.port = 8890
2019-11-19 20:21:07 +00:00
```
To serve files from a directory called ```my_document_root```, rather than ```www```:
2021-08-18 18:15:10 +00:00
```python
web.server.document_root = "my_document_root"
2019-11-19 20:21:07 +00:00
```
To see client/server communication:
```python
web.server.debug = True
```
2021-08-18 18:15:10 +00:00
## When the Web Server Starts
2024-05-23 15:13:50 +00:00
The web server, if enabled, will start during sim initialization. When it does, it will look for the specified document root directory. By default that’ s `“www”` . If root directory doesn’ t exist, one will be created with a simple `index.html` file , a style sheet, and a couple of directories.
2019-11-19 20:21:07 +00:00
2021-08-18 18:15:10 +00:00
## Connecting to Your Web Server
2024-05-23 15:13:50 +00:00
Assuming that you accepted the default port, connect to ```http://localhost:8888/``` (```https://localhost:8888/``` if `ssl_enable=True` ) from your web browser. This will display the `index.html` file in your root directory.
2019-11-19 20:21:07 +00:00
## The Default Document Root Directory
2021-08-18 18:15:10 +00:00
The default document root directory that was initially created for you is minimal.
2019-11-19 20:21:07 +00:00
```
2021-08-18 18:15:10 +00:00
www/
index.html
style.css
apps/
images/
```
2019-11-19 20:21:07 +00:00
2024-05-23 15:13:50 +00:00
**index.html** is the file that’ s displayed when you connect to `http://localhost:8888/` .
2019-11-19 20:21:07 +00:00
2021-08-18 18:15:10 +00:00
**style.css** is a CSS style-sheet that’ s included by index.html to give it some pizzazz.
2019-11-19 20:21:07 +00:00
2021-08-18 18:15:10 +00:00
The **apps** directory contains links to some example html/javascript applications
in ```$TRICK_HOME/trick_source/web/apps```.
2019-11-19 20:21:07 +00:00
2021-08-18 18:15:10 +00:00
The **images** directory contains trick_icon.png.
2019-11-19 20:21:07 +00:00
2021-08-18 18:15:10 +00:00
**You are encouraged to add to, modify, and/or delete these files and directories to best suite the needs of your project.**
2019-11-19 20:21:07 +00:00
2022-08-15 19:16:29 +00:00
Continue to [Configuring Trick with Civetweb ](Configure-Civetweb )