simpleserver: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: simpleserver
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## Intro | |
| 2 | + | ||
| 3 | + | Simpleserver is a sample application that can be used to serve files using the HTTP protocol. While it's primary purpose is to showcase the possibilities of FCL-Web and the [[fphttpserver]] and [[fpwebfile]] units, it can be used as a small web server to aid in e.g. development of pas2js applications. | |
| 4 | + | ||
| 5 | + | ## Usage | |
| 6 | + | ||
| 7 | + | You can get an overview of the supported command-line arguments using the **-h** option: | |
| 8 | + | ||
| 9 | + | > ./simpleserver -h | |
| 10 | + | Usage simpleserver [options] | |
| 11 | + | Where options is one or more of : | |
| 12 | + | -A --api=path,secret Activate location API on path, using secret as accepted bearer token. | |
| 13 | + | -a --max-age=age Set max-age expiry header on returned file requests. | |
| 14 | + | -c --config=file Ini configuration file (default: simpleserver.ini) | |
| 15 | + | -b --background fork to background | |
| 16 | + | -d --directory=dir Base directory from which to serve files. | |
| 17 | + | Default is current working directory: /home/michael/FPC/trunk/packages/fcl-web/examples/simpleserver | |
| 18 | + | -e --echo Activate /echo URL. | |
| 19 | + | -h --help This help text | |
| 20 | + | -H --hostname=NAME Set hostname for self-signed SSL certificate | |
| 21 | + | -i --indexpage=name Directory index page to use (default: index.html) | |
| 22 | + | -m --mimetypes=file Path of mime.types. Loaded in addition to OS known types | |
| 23 | + | -n --noindexpage Do not allow index page. | |
| 24 | + | -p --port=NNNN TCP/IP port to listen on (default is 3000) | |
| 25 | + | -q --quiet Do not write diagnostic messages | |
| 26 | + | -Q --quit=PWD Register /quit URL. Send request with password variable equal to PWD to stop | |
| 27 | + | -s --ssl Use SSL | |
| 28 | + | -x --proxy=proxydef Add proxy definition. Definition is of form: | |
| 29 | + | name:BaseURL | |
| 30 | + | ||
| 31 | + | Config file is ini file, section [Server]. Key names are long option names | |
| 32 | + | Proxies are defined in section [Proxy], Key is name, value is URL | |
| 33 | + | Locations are defined in section [Locations], Key is location name, value is path | |
| 34 | + | ||
| 35 | + | ### Command-line options | |
| 36 | + | ||
| 37 | + | The command-line options are used as follows: | |
| 38 | + | ||
| 39 | + | -A --api=path,secret | |
| 40 | + | Specifying this option activates the location API [[fpwebfile]] on *path*, using *secret* as accepted bearer token. | |
| 41 | + | ||
| 42 | + | -a --max-age=age | |
| 43 | + | This option sets the max-age expiry header on returned file requests The *age* argument is a number in seconds. | |
| 44 | + | ||
| 45 | + | -c --config=file | |
| 46 | + | Specify the name of an Ini configuration file. | |
| 47 | + | ||
| 48 | + | If this option is not specified, the program will look for a file *simpleserver.ini* in the current working directory and load that if it exists. | |
| 49 | + | ||
| 50 | + | -b --background | |
| 51 | + | Available on Unix only, this will fork the program so it runs in the background | |
| 52 | + | ||
| 53 | + | -d --directory=dir | |
| 54 | + | Set the base directory from which to serve files. | |
| 55 | + | ||
| 56 | + | The default is current working directory. | |
| 57 | + | ||
| 58 | + | Additional locations can be specified in the **Locations** section of the config file. | |
| 59 | + | ||
| 60 | + | -e --echo; | |
| 61 | + | When you provide this option, it will activate the /echo URL. | |
| 62 | + | ||
| 63 | + | This URL will simply echo the incoming request. | |
| 64 | + | ||
| 65 | + | -h --help | |
| 66 | + | Prints the help text as shown above. | |
| 67 | + | ||
| 68 | + | -H --hostname=NAME | |
| 69 | + | When SSL is enabled, this option sets the hostname for the self-signed SSL certificate. | |
| 70 | + | ||
| 71 | + | -i --indexpage=name | |
| 72 | + | Set the directory index page to use when the URL refers to a directory. | |
| 73 | + | ||
| 74 | + | The default is *index.html* | |
| 75 | + | ||
| 76 | + | -m --mimetypes=file; | |
| 77 | + | Set the path of the *mime.types* file. This file is Loaded in addition to OS known types. | |
| 78 | + | ||
| 79 | + | On Windows, the server will look for and load a 'mime.types' file in the directory where the program is located. | |
| 80 | + | ||
| 81 | + | -n --noindexpage | |
| 82 | + | Do not allow to serve an index page. | |
| 83 | + | ||
| 84 | + | -p --port=NNNN | |
| 85 | + | Set the TCP/IP port to listen on (the default port is 3000) | |
| 86 | + | ||
| 87 | + | -q --quiet | |
| 88 | + | Do not write diagnostic messages. By default a log message is written for every file served. | |
| 89 | + | ||
| 90 | + | -Q --quit=PWD | |
| 91 | + | Register the /quit URL. | |
| 92 | + | ||
| 93 | + | If you send a request with password variable equal to PWD, the server will stop executing. | |
| 94 | + | ||
| 95 | + | -s --ssl | |
| 96 | + | Use this option to enable SSL. You must also specify the *-H* option if you use this. | |
| 97 | + | ||
| 98 | + | -x --proxy=proxydef | |
| 99 | + | Add a proxy definition. This option can be specified multiple times. | |
| 100 | + | ||
| 101 | + | Each definition is of the form *name=URL* where name is the first component of a URL path, the second is the URL to forward the request to. | |
| 102 | + | ||
| 103 | + | ### Config file | |
| 104 | + | ||
| 105 | + | The configuration file can have 3 sections: | |
| 106 | + | ||
| 107 | + | Server | |
| 108 | + | ||
| 109 | + | This section contains the configuration variables. | |
| 110 | + | ||
| 111 | + | Locations | |
| 112 | + | ||
| 113 | + | This section contains the configuration variables. | |
| 114 | + | ||
| 115 | + | Proxy | |
| 116 | + | ||
| 117 | + | This section contains the definition of proxy URLS. | |
| 118 | + | ||
| 119 | + | #### Config section | |
| 120 | + | ||
| 121 | + | The following keys are supported | |
| 122 | + | ||
| 123 | + | Port (integer) | |
| 124 | + | Set the port to listen on | |
| 125 | + | ||
| 126 | + | Directory (string) | |
| 127 | + | Directory to serve files from | |
| 128 | + | ||
| 129 | + | IndexPage (string) | |
| 130 | + | Name of directory index page (default 'index.html') | |
| 131 | + | ||
| 132 | + | HostName (string) | |
| 133 | + | Name of host when enabling SSL | |
| 134 | + | ||
| 135 | + | Mimetypes (string) | |
| 136 | + | Name of *mime.types* file to load. | |
| 137 | + | ||
| 138 | + | SSL (boolean) | |
| 139 | + | Enable SSL mode or not. | |
| 140 | + | ||
| 141 | + | Quiet (boolean) | |
| 142 | + | Do not output diagnostic messages. | |
| 143 | + | ||
| 144 | + | Quit (string) | |
| 145 | + | If not-empty, register /quit url with value as password. | |
| 146 | + | ||
| 147 | + | Echo (boolean) | |
| 148 | + | If true, register /echo to echo requests. | |
| 149 | + | ||
| 150 | + | NoIndexPage (boolean) | |
| 151 | + | Do not serve index pages. | |
| 152 | + | ||
| 153 | + | Background (boolean) | |
| 154 | + | Unix only: Fork to background process. | |
| 155 | + | ||
| 156 | + | MaxAge (integer) | |
| 157 | + | Specify max age (in seconds) of files. | |
| 158 | + | ||
| 159 | + | API (string) | |
| 160 | + | Enable locations API. The value is in the form *path,secret*. | |
| 161 | + | ||
| 162 | + | The path is the first component of the URL at which the location REST API is served. | |
| 163 | + | ||
| 164 | + | The 'secret' is used to secure the API: every request must have the value of secret in the URL as either a *Authorization* header bearer token, or as the APIKey query parameter. | |
| 165 | + | ||
| 166 | + | #### Proxy section | |
| 167 | + | ||
| 168 | + | Every key in this section is registered as a proxy URL. This means the values must be valid URLS. | |
| 169 | + | ||
| 170 | + | Example: | |
| 171 | + | ||
| 172 | + | [Proxy] | |
| 173 | + | drive=http://drive.google.com/ | |
| 174 | + | ||
| 175 | + | so an url | |
| 176 | + | ||
| 177 | + | http://localhost:3030/drive/my/file/url.txt | |
| 178 | + | ||
| 179 | + | will be forwarded to | |
| 180 | + | ||
| 181 | + | http://drive.google.com/my/file/url.txt | |
| 182 | + | ||
| 183 | + | #### Locations section | |
| 184 | + | ||
| 185 | + | Every key in this section is registered as a file location URL. This means the values must be valid paths. | |
| 186 | + | ||
| 187 | + | Example: | |
| 188 | + | ||
| 189 | + | [Locations] | |
| 190 | + | temp=/tmp | |
| 191 | + | ||
| 192 | + | so an url | |
| 193 | + | ||
| 194 | + | http://localhost:3030/temp/backup.log | |
| 195 | + | ||
| 196 | + | will serve the file | |
| 197 | + | ||
| 198 | + | /tmp/backup.log | |
| 199 | + | ||
| 200 | + | --- | |
| 201 | + | *From the Free Pascal wiki, page "simpleserver", as it stood on 2021-09-04 after a change by Michael, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
