help.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. package engine
  2. import (
  3. "fmt"
  4. "os"
  5. )
  6. const generalHelpText = `Available functions:
  7. Data structures
  8. // Get or create database-backed Set (takes a name, returns a set object)
  9. Set(string) -> userdata
  10. // Add an element to the set
  11. set:add(string)
  12. // Remove an element from the set
  13. set:del(string)
  14. // Check if a set contains a value.
  15. // Returns true only if the value exists and there were no errors.
  16. set:has(string) -> bool
  17. // Get all members of the set
  18. set:getall() -> table
  19. // Remove the set itself. Returns true if successful.
  20. set:remove() -> bool
  21. // Clear the set. Returns true if successful.
  22. set:clear() -> bool
  23. // Get or create a database-backed List (takes a name, returns a list object)
  24. List(string) -> userdata
  25. // Add an element to the list
  26. list:add(string)
  27. // Get all members of the list
  28. list:getall() -> table
  29. // Get the last element of the list. The returned value can be empty
  30. list:getlast() -> string
  31. // Get the N last elements of the list
  32. list:getlastn(number) -> table
  33. // Remove the list itself. Returns true if successful.
  34. list:remove() -> bool
  35. // Clear the list. Returns true if successful.
  36. list:clear() -> bool
  37. // Return all list elements (expected to be JSON strings) as a JSON list
  38. list:json() -> string
  39. // Get or create a database-backed HashMap
  40. // (takes a name, returns a hash map object)
  41. HashMap(string) -> userdata
  42. // For a given element id (for instance a user id), set a key.
  43. // Returns true if successful.
  44. hash:set(string, string, string) -> bool
  45. // For a given element id (for instance a user id), and a key, return a value.
  46. hash:get(string, string) -> string
  47. // For a given element id (for instance a user id), and a key,
  48. // check if the key exists in the hash map.
  49. hash:has(string, string) -> bool
  50. // For a given element id (for instance a user id), check if it exists.
  51. hash:exists(string) -> bool
  52. // Get all keys of the hash map
  53. hash:getall() -> table
  54. // Remove a key for an entry in a hash map. Returns true if successful
  55. hash:delkey(string, string) -> bool
  56. // Remove an element (for instance a user). Returns true if successful
  57. hash:del(string) -> bool
  58. // Remove the hash map itself. Returns true if successful.
  59. hash:remove() -> bool
  60. // Clear the hash map. Returns true if successful.
  61. hash:clear() -> bool
  62. // Get or create a database-backed KeyValue collection
  63. // (takes a name, returns a key/value object)
  64. KeyValue(string) -> userdata
  65. // Set a key and value. Returns true if successful.
  66. kv:set(string, string) -> bool
  67. // Takes a key, returns a value. May return an empty string.
  68. kv:get(string) -> string
  69. // Takes a key, returns the value+1.
  70. // Creates a key/value and returns "1" if it did not already exist.
  71. kv:inc(string) -> string
  72. // Remove a key. Returns true if successful.
  73. kv:del(string) -> bool
  74. // Remove the KeyValue itself. Returns true if successful.
  75. kv:remove() -> bool
  76. // Clear the KeyValue. Returns true if successful.
  77. kv:clear() -> bool
  78. Live server configuration
  79. // Reset the URL prefixes and make everything *public*.
  80. ClearPermissions()
  81. // Add an URL prefix that will have *admin* rights.
  82. AddAdminPrefix(string)
  83. // Add an URL prefix that will have *user* rights.
  84. AddUserPrefix(string)
  85. // Provide a lua function that will be used as the permission denied handler.
  86. DenyHandler(function)
  87. // Direct the logging to the given filename. If the filename is an empty
  88. // string, direct logging to stderr. Returns true if successful.
  89. LogTo(string) -> bool
  90. // Add a reverse proxy given a path prefix and an endpoint URL
  91. AddReverseProxy(string, string)
  92. Output
  93. // Log the given strings as info. Takes a variable number of strings.
  94. log(...)
  95. // Log the given strings as a warning. Takes a variable number of strings.
  96. warn(...)
  97. // Log the given strings as an error. Takes a variable number of strings.
  98. err(...)
  99. // Output text. Takes a variable number of strings.
  100. print(...)
  101. // Output rendered HTML given Markdown. Takes a variable number of strings.
  102. mprint(...)
  103. // Output rendered HTML given Amber. Takes a variable number of strings.
  104. aprint(...)
  105. // Output rendered CSS given GCSS. Takes a variable number of strings.
  106. gprint(...)
  107. // Output rendered JavaScript given JSX for HyperApp. Takes a variable number of strings.
  108. hprint(...)
  109. // Output rendered JavaScript given JSX for React. Takes a variable number of strings.
  110. jprint(...)
  111. // Output a Pongo2 template and key/value table as rendered HTML. Use "{{ key }}" to insert a key.
  112. poprint(string[, table])
  113. // Output a simple HTML page with a message, title and theme.
  114. msgpage(string[, string][, string])
  115. Cache
  116. CacheInfo() -> string // Return information about the file cache.
  117. ClearCache() // Clear the file cache.
  118. preload(string) -> bool // Load a file into the cache, returns true on success.
  119. JSON
  120. // Use, or create, a JSON document/file.
  121. JFile(filename) -> userdata
  122. // Retrieve a string, given a valid JSON path. May return an empty string.
  123. jfile:getstring(string) -> string
  124. // Retrieve a JSON node, given a valid JSON path. May return nil.
  125. jfile:getnode(string) -> userdata
  126. // Retrieve a value, given a valid JSON path. May return nil.
  127. jfile:get(string) -> value
  128. // Change an entry given a JSON path and a value. Returns true if successful.
  129. jfile:set(string, string) -> bool
  130. // Given a JSON path (optional) and JSON data, add it to a JSON list.
  131. // Returns true if successful.
  132. jfile:add([string, ]string) -> bool
  133. // Removes a key in a map in a JSON document. Returns true if successful.
  134. jfile:delkey(string) -> bool
  135. // Convert a Lua table with strings or ints to JSON.
  136. // Takes an optional number of spaces to indent the JSON data.
  137. json(table[, number]) -> string
  138. // Create a JSON document node.
  139. JNode() -> userdata
  140. // Add JSON data to a node. The first argument is an optional JSON path.
  141. // The second argument is a JSON data string. Returns true on success.
  142. // "x" is the default JSON path.
  143. jnode:add([string, ]string) ->
  144. // Given a JSON path, retrieves a JSON node.
  145. jnode:get(string) -> userdata
  146. // Given a JSON path, retrieves a JSON string.
  147. jnode:getstring(string) -> string
  148. // Given a JSON path and a JSON string, set the value.
  149. jnode:set(string, string)
  150. // Given a JSON path, remove a key from a map.
  151. jnode:delkey(string) -> bool
  152. // Return the JSON data, nicely formatted.
  153. jnode:pretty() -> string
  154. // Return the JSON data, as a compact string.
  155. jnode:compact() -> string
  156. // Sends JSON data to the given URL. Returns the HTTP status code as a string.
  157. // The content type is set to "application/json;charset=utf-8".
  158. // The second argument is an optional authentication token that is used for the
  159. // Authorization header field. Uses HTTP POST.
  160. jnode:POST(string[, string]) -> string
  161. // Sends JSON data to the given URL. Returns the HTTP status code as a string.
  162. // The content type is set to "application/json;charset=utf-8".
  163. // The second argument is an optional authentication token that is used for the
  164. // Authorization header field. Uses HTTP PUT.
  165. jnode:PUT(string[, string]) -> string
  166. // Alias for jnode:POST
  167. jnode:send(string[, string]) -> string
  168. // Fetches JSON over HTTP given an URL that starts with http or https.
  169. // The JSON data is placed in the JNode. Returns the HTTP status code as a string.
  170. jnode:GET(string) -> string
  171. // Alias for jnode:GET
  172. jnode:receive(string) -> string
  173. // Convert from a simple Lua table to a JSON string
  174. JSON(table) -> string
  175. HTTP Requests
  176. // Create a new HTTP Client object
  177. HTTPClient() -> userdata
  178. // Select Accept-Language (ie. "en-us")
  179. hc:SetLanguage(string)
  180. // Set the request timeout (in milliseconds)
  181. hc:SetTimeout(number)
  182. // Set a cookie (name and value)
  183. hc:SetCookie(string, string)
  184. // Set the user agent (ie. "curl")
  185. hc:SetUserAgent(string)
  186. // Perform a HTTP GET request. First comes the URL, then an optional table with
  187. // URL paramets, then an optional table with HTTP headers.
  188. hc:Get(string, [table], [table]) -> string
  189. // Perform a HTTP POST request. It's the same arguments as for hc:Get, except
  190. // the fourth optional argument is the POST body.
  191. hc:Post(string, [table], [table], [string]) -> string
  192. // Like hc:Get, except the first argument is the HTTP method (like "PUT")
  193. hc:Do(string, string, [table], [table]) -> string
  194. // Shorthand for HTTPClient():Get(). Retrieve an URL, with optional tables for
  195. // URL parameters and HTTP headers.
  196. GET(string, [table], [table]) -> string
  197. // Shorthand for HTTPClient():Post(). Post to an URL, with optional tables for
  198. // URL parameters and HTTP headers, followed by a string for the body.
  199. POST(string, [table], [table], [string]) -> string
  200. // Shorthand for HTTPClient():Do(). Like Get, but the first argument is the
  201. // method, like ie. "PUT".
  202. DO(string, string, [table], [table]) -> string
  203. Plugins
  204. // Load a plugin given the path to an executable. Returns true if successful.
  205. // Will return the plugin help text if called on the Lua prompt. Pass true as
  206. // the last argument to keep it running.
  207. Plugin(string, [bool]) -> bool
  208. // Returns the Lua code as returned by the Lua.Code function in the plugin,
  209. // given a plugin path. Pass true as the last argument to keep it running.
  210. // May return an empty string.
  211. PluginCode(string, [bool]) -> string
  212. // Takes a plugin path, function name and arguments. Returns an empty string
  213. // if the function call fails, or the results as a JSON string if successful.
  214. CallPlugin(string, string, ...) -> string
  215. Code libraries
  216. // Create or use a code library object. Takes an optional data structure name.
  217. CodeLib([string]) -> userdata
  218. // Given a namespace and Lua code, add the given code to the namespace.
  219. // Returns true if successful.
  220. codelib:add(string, string) -> bool
  221. // Given a namespace and Lua code, set the given code as the only code
  222. // in the namespace. Returns true if successful.
  223. codelib:set(string, string) -> bool
  224. // Given a namespace, return Lua code, or an empty string.
  225. codelib:get(string) -> string
  226. // Import (eval) code from the given namespace into the current Lua state.
  227. // Returns true if successful.
  228. codelib:import(string) -> bool
  229. // Completely clear the code library. Returns true if successful.
  230. codelib:clear() -> bool
  231. Various
  232. // Return a string with various server information
  233. ServerInfo() -> string
  234. // Return the version string for the server
  235. version() -> string
  236. // Tries to extract and print the contents of the given Lua values
  237. pprint(...)
  238. // Sleep the given number of seconds (can be a float)
  239. sleep(number)
  240. // Return the number of nanoseconds from 1970 ("Unix time")
  241. unixnano() -> number
  242. // Convert Markdown to HTML
  243. markdown(string) -> string
  244. // Query a PostgreSQL database with a query and a connection string.
  245. // Default connection string: "host=localhost port=5432 user=postgres dbname=test sslmode=disable"
  246. PQ([string], [string]) -> table
  247. // Query a MSSQL database with a query and a connection string.
  248. // Default connection string: "server=localhost;user=user;password=password,port=1433"
  249. MSSQL([string], [string]) -> table
  250. REPL-only
  251. // Output the current working directory
  252. cwd | pwd
  253. // Output the current file or directory that is being served
  254. serverdir | serverfile
  255. // Exit Algernon
  256. exit | halt | quit | shutdown
  257. Extra
  258. // Takes a Python filename, executes the script with the "python" binary in the Path.
  259. // Returns the output as a Lua table, where each line is an entry.
  260. py(string) -> table
  261. // Takes one or more system commands (possibly separated by ";") and runs them.
  262. // Returns the output lines as a table.
  263. run(string) -> table
  264. // Lists the keys and values of a Lua table. Returns a string.
  265. // Lists the contents of the global namespace "_G" if no arguments are given.
  266. dir([table]) -> string
  267. `
  268. const usageMessage = `
  269. Type "webhelp" for an overview of functions that are available when
  270. handling requests. Or "confighelp" for an overview of functions that are
  271. available when configuring an Algernon application.
  272. `
  273. const webHelpText = `Available functions:
  274. Handling users and permissions
  275. // Check if the current user has "user" rights
  276. UserRights() -> bool
  277. // Check if the given username exists (does not check unconfirmed users)
  278. HasUser(string) -> bool
  279. // Check if the given username exists in the list of unconfirmed users
  280. HasUnconfirmedUser(string) -> bool
  281. // Get the value from the given boolean field
  282. // Takes a username and field name
  283. BooleanField(string, string) -> bool
  284. // Save a value as a boolean field
  285. // Takes a username, field name and boolean value
  286. SetBooleanField(string, string, bool)
  287. // Check if a given username is confirmed
  288. IsConfirmed(string) -> bool
  289. // Check if a given username is logged in
  290. IsLoggedIn(string) -> bool
  291. // Check if the current user has "admin rights"
  292. AdminRights() -> bool
  293. // Check if a given username is an admin
  294. IsAdmin(string) -> bool
  295. // Get the username stored in a cookie, or an empty string
  296. UsernameCookie() -> string
  297. // Store the username in a cookie, returns true if successful
  298. SetUsernameCookie(string) -> bool
  299. // Clear the login cookie
  300. ClearCookie()
  301. // Get a table containing all usernames
  302. AllUsernames() -> table
  303. // Get the email for a given username, or an empty string
  304. Email(string) -> string
  305. // Get the password hash for a given username, or an empty string
  306. PasswordHash(string) -> string
  307. // Get all unconfirmed usernames
  308. AllUnconfirmedUsernames() -> table
  309. // Get the existing confirmation code for a given user,
  310. // or an empty string. Takes a username.
  311. ConfirmationCode(string) -> string
  312. // Add a user to the list of unconfirmed users.
  313. // Takes a username and a confirmation code.
  314. // Remember to also add a user, when registering new users.
  315. AddUnconfirmed(string, string)
  316. // Remove a user from the list of unconfirmed users. Takes a username.
  317. RemoveUnconfirmed(string)
  318. // Mark a user as confirmed. Takes a username.
  319. MarkConfirmed(string)
  320. // Removes a user. Takes a username.
  321. RemoveUser(string)
  322. // Make a user an admin. Takes a username.
  323. SetAdminStatus(string)
  324. // Make an admin user a regular user. Takes a username.
  325. RemoveAdminStatus(string)
  326. // Add a user. Takes a username, password and email.
  327. AddUser(string, string, string)
  328. // Set a user as logged in on the server (not cookie). Takes a username.
  329. SetLoggedIn(string)
  330. // Set a user as logged out on the server (not cookie). Takes a username.
  331. SetLoggedOut(string)
  332. // Log in a user, both on the server and with a cookie. Takes a username.
  333. Login(string)
  334. // Log out a user, on the server (which is enough). Takes a username.
  335. Logout(string)
  336. // Get the current username, from the cookie
  337. Username() -> string
  338. // Get the current cookie timeout. Takes a username.
  339. CookieTimeout(string) -> number
  340. // Set the current cookie timeout. Takes a timeout, in seconds.
  341. SetCookieTimeout(number)
  342. // Get the current server-wide cookie secret, for persistent logins
  343. CookieSecret() -> string
  344. // Set the current server-side cookie secret, for persistent logins
  345. SetCookieSecret(string)
  346. // Get the current password hashing algorithm (bcrypt, bcrypt+ or sha256)
  347. PasswordAlgo() -> string
  348. // Set the current password hashing algorithm (bcrypt, bcrypt+ or sha256)
  349. // Takes a string
  350. SetPasswordAlgo(string)
  351. // Hash the password
  352. // Takes a username and password (username can be used for salting)
  353. HashPassword(string, string) -> string
  354. // Change the password for a user, given a username and a new password
  355. SetPassword(string, string)
  356. // Check if a given username and password is correct
  357. // Takes a username and password
  358. CorrectPassword(string, string) -> bool
  359. // Checks if a confirmation code is already in use
  360. // Takes a confirmation code
  361. AlreadyHasConfirmationCode(string) -> bool
  362. // Find a username based on a given confirmation code,
  363. // or returns an empty string. Takes a confirmation code
  364. FindUserByConfirmationCode(string) -> string
  365. // Mark a user as confirmed
  366. // Takes a username
  367. Confirm(string)
  368. // Mark a user as confirmed, returns true if successful
  369. // Takes a confirmation code
  370. ConfirmUserByConfirmationCode(string) -> bool
  371. // Set the minimum confirmation code length
  372. // Takes the minimum number of characters
  373. SetMinimumConfirmationCodeLength(number)
  374. // Generates a unique confirmation code, or an empty string
  375. GenerateUniqueConfirmationCode() -> string
  376. File uploads
  377. // Creates a file upload object. Takes a form ID (from a POST request) as the
  378. // first parameter. Takes an optional maximum upload size (in MiB) as the
  379. // second parameter. Returns nil and an error string on failure, or userdata
  380. // and an empty string on success.
  381. UploadedFile(string[, number]) -> userdata, string
  382. // Return the uploaded filename, as specified by the client
  383. uploadedfile:filename() -> string
  384. // Return the size of the data that has been received
  385. uploadedfile:size() -> number
  386. // Return the mime type of the uploaded file, as specified by the client
  387. uploadedfile:mimetype() -> string
  388. // Return the full textual content of the uploaded file
  389. uploadedfile:content() -> string
  390. // Save the uploaded data locally. Takes an optional filename.
  391. uploadedfile:save([string]) -> bool
  392. // Save the uploaded data as the client-provided filename, in the specified
  393. // directory. Takes a relative or absolute path. Returns true on success.
  394. uploadedfile:savein(string) -> bool
  395. Handling requests
  396. // Set the Content-Type for a page.
  397. content(string)
  398. // Return the requested HTTP method (GET, POST etc).
  399. method() -> string
  400. // Output text to the browser/client. Takes a variable number of strings.
  401. print(...)
  402. // Return the requested URL path.
  403. urlpath() -> string
  404. // Return the HTTP header in the request, for a given key, or an empty string.
  405. header(string) -> string
  406. // Set an HTTP header given a key and a value.
  407. setheader(string, string)
  408. // Return the HTTP headers, as a table.
  409. headers() -> table
  410. // Return the HTTP body in the request
  411. // (will only read the body once, since it's streamed).
  412. body() -> string
  413. // Set a HTTP status code (like 200 or 404).
  414. // Must be used before other functions that writes to the client!
  415. status(number)
  416. // Set a HTTP status code and output a message (optional).
  417. error(number[, string])
  418. // Return the directory where the script is running. If a filename (optional)
  419. // is given, then the path to where the script is running, joined with a path
  420. // separator and the given filename, is returned.
  421. scriptdir([string]) -> string
  422. // Return the directory where the server is running. If a filename (optional)
  423. // is given, then the path to where the server is running, joined with a path
  424. // separator and the given filename, is returned.
  425. serverdir([string]) -> string
  426. // Serve a file that exists in the same directory as the script.
  427. serve(string)
  428. // Serve a Pongo2 template file, with an optional table with key/values.
  429. serve2(string[, table)
  430. // Return the rendered contents of a file that exists in the same directory
  431. // as the script. Takes a filename.
  432. render(string) -> string
  433. // Return a table with keys and values as given in a posted form, or as given
  434. // in the URL ("/some/page?x=7" makes "x" with the value "7" available).
  435. formdata() -> table
  436. // Redirect to an absolute or relative URL. Also takes a HTTP status code.
  437. redirect(string[, number])
  438. // Permanently redirect to an absolute or relative URL. Uses status code 302.
  439. permanent_redirect(string)
  440. // Send "Connection: close" as a header to the client, flush the body and also
  441. // stop Lua functions from writing more data to the HTTP body.
  442. close()
  443. // Transmit what has been outputted so far, to the client.
  444. flush()
  445. `
  446. const configHelpText = `Available functions:
  447. Only available when used in serverconf.lua
  448. // Set the default address for the server on the form [host][:port].
  449. SetAddr(string)
  450. // Reset the URL prefixes and make everything *public*.
  451. ClearPermissions()
  452. // Add an URL prefix that will have *admin* rights.
  453. AddAdminPrefix(string)
  454. // Add an URL prefix that will have *user* rights.
  455. AddUserPrefix(string)
  456. // Provide a lua function that will be used as the permission denied handler.
  457. DenyHandler(function)
  458. // Provide a lua function that will be run once,
  459. // when the server is ready to start serving.
  460. OnReady(function)
  461. // Use a Lua file for setting up HTTP handlers instead of using the directory structure.
  462. ServerFile(string) -> bool
  463. // Get the cookie secret from the server configuration.
  464. CookieSecret() -> string
  465. // Set the cookie secret that will be used when setting and getting browser cookies.
  466. SetCookieSecret(string)
  467. `
  468. func generateUsageFunction(ac *Config) func() {
  469. return func() {
  470. fmt.Println("\n" + ac.versionString + "\n\n" + ac.description)
  471. var quicExample string
  472. var quicUsageOrMessage string
  473. var quicFinalMessage string
  474. // Prepare and/or output a message, depending on if QUIC support is compiled in or not
  475. if quicEnabled {
  476. quicUsageOrMessage = "\n -u Serve over QUIC / HTTP3."
  477. quicExample = "\n Serve the current dir over QUIC, port 7000, no banner:\n algernon -s -u -n . :7000\n"
  478. } else {
  479. quicFinalMessage = "\n\nThis Algernon executable was built without QUIC support."
  480. }
  481. // Possible arguments are also, for backward compatibility:
  482. // server dir, server addr, certificate file, key file, redis addr and redis db index
  483. // They are not mentioned here, but are possible to use, in that strict order.
  484. fmt.Println(`
  485. Syntax:
  486. algernon [flags] [file or directory to serve] [host][:port]
  487. Available flags:
  488. -a, --autorefresh Enable event server and auto-refresh feature.
  489. Sets cache mode to "images".
  490. -b, --bolt Use "` + ac.defaultBoltFilename + `"
  491. for the Bolt database.
  492. -c, --statcache Speed up responses by caching os.Stat.
  493. Only use if served files will not be removed.
  494. -d, --debug Enable debug mode (show errors in the browser).
  495. -e, --dev Development mode: Enables Debug mode, uses
  496. regular HTTP, Bolt and sets cache mode "dev".
  497. -h, --help This help text
  498. -l, --lua Don't serve anything, just present the Lua REPL.
  499. -m View the given Markdown file in the browser.
  500. Quits after the file has been served once.
  501. ("-m" is equivalent to "-q -o -z").
  502. -n, --nobanner Don't display a colorful banner at start.
  503. -o, --open=EXECUTABLE Open the served URL with ` + ac.defaultOpenExecutable + `,
  504. or with the given application.
  505. -p, --prod Serve HTTP/2+HTTPS on port 443. Serve regular
  506. HTTP on port 80. Uses /srv/algernon for files.
  507. Disables debug mode. Disables auto-refresh.
  508. Enables server mode. Sets cache to "prod".
  509. -q, --quiet Don't output anything to stdout or stderr.
  510. -r, --redirect Redirect HTTP traffic to HTTPS, if both are enabled.
  511. -s, --server Server mode (disable debug + interactive mode).
  512. -t, --httponly Serve regular HTTP.` + quicUsageOrMessage + `
  513. -v, --version Application name and version
  514. -V, --verbose Slightly more verbose logging.
  515. -z, --quit Quit after the first request has been served.
  516. --accesslog=FILENAME Access log filename. Logged in Combined Log Format (CLF).
  517. --addr=[HOST][:PORT] Server host and port ("` + ac.defaultWebColonPort + `" is default)
  518. --boltdb=FILENAME Use a specific file for the Bolt database
  519. --cache=MODE Sets a cache mode. The default is "on".
  520. "on" - Cache everything.
  521. "dev" - Everything, except Amber,
  522. Lua, GCSS, Markdown and JSX.
  523. "prod" - Everything, except Amber and Lua.
  524. "small" - Like "prod", but only files <= 64KB.
  525. "images" - Only images (png, jpg, gif, svg).
  526. "off" - Disable caching.
  527. --cachesize=N Set the total cache size, in bytes.
  528. --cert=FILENAME TLS certificate, if using HTTPS.
  529. --conf=FILENAME Lua script with additional configuration.
  530. --clear Clear the default URI prefixes that are used
  531. when handling permissions.
  532. --cookiesecret=STRING Secret that will be used for login cookies.
  533. --ctrld Press ctrl-d twice to exit the REPL.
  534. --dbindex=INDEX Redis database index (0 is default).
  535. --dir=DIRECTORY Set the server directory
  536. --domain Serve files from the subdirectory with the same
  537. name as the requested domain.
  538. --eventrefresh=DURATION How often the event server should refresh
  539. (the default is "` + ac.defaultEventRefresh + `").
  540. --eventserver=[HOST][:PORT] SSE server address (for filesystem changes).
  541. --http2only Serve HTTP/2, without HTTPS.
  542. --internal=FILENAME Internal log file (can be a bit verbose).
  543. --key=FILENAME TLS key, if using HTTPS.
  544. --largesize=N Threshold for not reading static files into memory, in bytes.
  545. --letsencrypt Use certificates provided by Let's Encrypt for all served
  546. domains and serve over regular HTTPS by using CertMagic.
  547. --limit=N Limit clients to N requests per second
  548. (the default is ` + ac.defaultLimitString + `).
  549. --log=FILENAME Log to a file instead of to the console.
  550. --maria=DSN Use the given MariaDB or MySQL host/database.
  551. --mariadb=NAME Use the given MariaDB or MySQL database name.
  552. --ncsa=FILENAME Alternative access log filename. Logged in Common Log Format (NCSA).
  553. --nocache Another way to disable the caching.
  554. --nodb No database backend. (same as --boltdb=` + os.DevNull + `).
  555. --noheaders Don't use the security-related HTTP headers.
  556. --nolimit Disable rate limiting.
  557. --postgres=DSN Use the given PostgreSQL host/database.
  558. --postgresdb=NAME Use the given PostgreSQL database name.
  559. --redis=[HOST][:PORT] Use "` + ac.defaultRedisColonPort + `" for the Redis database.
  560. --rawcache Disable cache compression.
  561. --servername=STRING Custom HTTP header value for the Server field.
  562. --stricter Stricter HTTP headers (same origin policy).
  563. --theme=NAME Builtin theme to use for Markdown, error pages,
  564. directory listings and HyperApp apps.
  565. Possible values are: light, dark, bw, redbox, wing,
  566. material, neon or werc.
  567. --timeout=N Timeout when serving files, in seconds.
  568. --watchdir=DIRECTORY Enables auto-refresh for only this directory.
  569. -x, --simple Serve as regular HTTP, enable server mode and
  570. disable all features that requires a database.
  571. Example usage:
  572. For auto-refreshing a webpage while developing:
  573. algernon --dev --httponly --debug --autorefresh --bolt --server . :4000
  574. Serve /srv/mydomain.com and /srv/otherweb.com over HTTP and HTTPS + HTTP/2:
  575. algernon -c --domain --server --cachesize 67108864 --prod /srv
  576. ` + quicExample + `
  577. Serve the current directory over HTTP, port 3000. No limits, cache,
  578. permissions or database connections:
  579. algernon -x` + quicFinalMessage)
  580. }
  581. }