settings.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. const jsl = require("svjsl");
  2. const packageJSON = require("./package.json");
  3. const { getProp } = require("./src/env");
  4. const col = jsl.colors.fg;
  5. const bgc = jsl.colors.bg;
  6. /*
  7. * Notes:
  8. * - to change environment-dependent properties that use getProp(), go to './src/env.js'
  9. * - to change the environment, set the `NODE_ENV` environment variable (in the '.dotenv' file)
  10. */
  11. const settings = {
  12. debug: {
  13. verboseLogging: false, // set to true to enable extra debug output
  14. progressBarDisabled: true, // set to true to disable the progress bar - greatly improves readability of verbose debug output
  15. onlyLogErrors: true, // set to true to disable sending any console logs but error messages
  16. },
  17. info: {
  18. name: getProp("name"), // the name of JokeAPI
  19. desc: packageJSON.description, // the description of JokeAPI
  20. projGitHub: "https://github.com/Sv443-Network/JokeAPI", // URL to the project's GitHub page
  21. version: packageJSON.version, // the version as a string
  22. versionInt: packageJSON.version.split("."), // the version as a number array
  23. docsURL: getProp("baseUrl"), // the URL to the documentation of JokeAPI
  24. author: {
  25. name: packageJSON.author.name, // author name
  26. email: packageJSON.author.email, // author email
  27. website: packageJSON.author.url, // author website
  28. github: `https://github.com/${packageJSON.author.name}`, // author github page
  29. },
  30. privacyPolicyUrl: "https://sv443.net/privacypolicy/en",
  31. contribGuideUrl: "https://github.com/Sv443-Network/JokeAPI/blob/master/.github/Contributing.md",
  32. },
  33. wrapper: {
  34. mainFilePath: "./src/main.js", // main script file
  35. skipWrapping: true, // whether or not to skip the wrapping through node-wrap
  36. wrapperSettings: {
  37. console: true, // whether Node-Wrap should log to the console
  38. crashTimeout: 2000, // timeout (in ms) until the process should be restarted after a crash
  39. logFile: "./data/logs/wrapper.log", // Node-Wrap log file
  40. logTimestamp: true, // whether to add a timestamp to the log
  41. restartOnCrash: true, // whether to restart the process after a crash
  42. restartTimeout: 0, // timeout (in ms) until the process should be started again after a restart has been requested
  43. },
  44. },
  45. init: {
  46. initDirs: [ // directories that should be generated if they don't exist - paths relative to root of project - doesn't necessarily need trailing slash
  47. "./data/logs",
  48. "./data/submissions",
  49. "./docs/compiled",
  50. "./data/lists"
  51. ],
  52. exitSignals: [ // all signals that should cause a soft exit
  53. "SIGINT",
  54. "SIGTERM"
  55. ],
  56. },
  57. logging: {
  58. logChar: "▌", // character that gets logged on each request
  59. spacerAfter: 10, // after how many logged requests a spacer should be put - set to 0 to disable
  60. disableLogging: false, // set to true to disable logging a character on each request
  61. blacklistLoggingEnabled: true, // whether or not to log the character when an IP is on the blacklist
  62. },
  63. jokes: {
  64. jokesFormatVersion: 3, // current joke format version
  65. jokesFolderPath: "./data/jokes/", // path to the jokes folder - needs trailing slash
  66. jokeSubmissionURL: `${getProp("baseUrl")}#submit`, // joke submission url
  67. jokeSubmissionPath: "./data/submissions/", // path to a directory where joke submissions should be saved to - needs trailing slash
  68. submissions: {
  69. timeFrame: 60, // time frame of submission rate limiter (in seconds)
  70. rateLimiting: 5, // how many requests per timeframe should be allowed
  71. invalidCharRegex: /(?![\u0000-\u0fff])./gm, // eslint-disable-line no-control-regex
  72. minLength: 2, // minimum amount of characters needed in joke submissions (per property)
  73. },
  74. jokesTemplateFile: "template.json", // relative to "jokes.jokesFolderPath"
  75. possible: {
  76. anyCategoryName: "Any", // the name of the "Any" category - case insensitive / readable name
  77. categories: [ // all categories (excluding "Any") - case insensitive / readable name
  78. "Misc",
  79. "Programming",
  80. "Dark",
  81. "Pun",
  82. "Spooky",
  83. "Christmas"
  84. ],
  85. categoryAliases: { // aliases of categories. Alias at key gets resolved to category at value. Value has to be present in the "categories" array above - case sensitive / readable names
  86. "Miscellaneous": "Misc",
  87. "Coding": "Programming",
  88. "Development": "Programming",
  89. "Halloween": "Spooky"
  90. },
  91. flags: [ // all flags - HAVE TO BE LOWER CASE!
  92. "nsfw",
  93. "religious",
  94. "political",
  95. "racist",
  96. "sexist",
  97. "explicit",
  98. ],
  99. formats: [ // all file formats - HAVE TO BE LOWER CASE!
  100. "json",
  101. "xml",
  102. "yaml",
  103. "txt",
  104. ],
  105. types: [ // all joke types - HAVE TO BE LOWER CASE!
  106. "single",
  107. "twopart"
  108. ],
  109. },
  110. fileFormatsPath: "./data/fileFormats.json", // path to the file formats file
  111. defaultFileFormat: {
  112. fileFormat: "json", // the default file format string
  113. mimeType: "application/json", // the default file format mime type
  114. },
  115. lastIDsMaxLength: 15, // the maximum amount of joke IDs that get saved to the blacklist-array
  116. jokeRandomizationAttempts: 25, // after how many attempts of selecting a random joke to stop trying
  117. splitChars: [ ",", "+", "-" ], // which characters should separate the values of parameters with support for multiple values
  118. splitCharRegex: /[,+-]/gm, // which characters should separate the values of parameters with support for multiple values
  119. maxAmount: 10, // the maximum amount of jokes that can be fetched with a single call to the get jokes endpoint
  120. encodeAmount: 5, // if more than this number of jokes is requested, encode them
  121. },
  122. httpServer: {
  123. port: getProp("httpPort"), // http server port
  124. allowCORS: true, // whether or not to allow Cross Origin Resource Sharing
  125. rateLimiting: 120, // amount of allowed requests per below defined timeframe
  126. timeFrame: 60, // timeframe in seconds
  127. urlPathOffset: 0, // example: "/jokeapi/info" with an offset of 1 will only start parsing the path beginning at "info" - an Apache reverse proxy will do this automatically though
  128. maxPayloadSize: 5120, // max size (in bytes) that will be accepted in a PUT request - if payload exceeds this size, it will abort with status 413
  129. maxUrlLength: 250, // max amount of characters of the URL - if the URL is longer than this, the request will abort with status 414
  130. disableCache: true, // whether or not to disable the cache - default: true (setting to false may prevent the users from getting new jokes)
  131. infoHeaders: true, // whether or not to add an informational header about JokeAPI to each request
  132. reverseProxy: true, // whether or not JokeAPI gets its requests from a reverse proxy
  133. startupTimeout: 30, // in seconds, timeout after which startup fails if the HTTP server couldn't start up (blocked port, etc.)
  134. ipSanitization: { // used to sanitize IP addresses so they can be used in file paths
  135. regex: /[^A-Za-z0-9\-_./]|^COM[0-9]([/.]|$)|^LPT[0-9]([/.]|$)|^PRN([/.]|$)|^CLOCK\$([/.]|$)|^AUX([/.]|$)|^NUL([/.]|$)|^CON([/.]|$)/gm,
  136. replaceChar: "#", // what character to use instead of illegal characters
  137. },
  138. ipHashing: {
  139. enabled: true, // hashes all IP addresses. If set to false, JokeAPI is not GDPR compliant anymore!
  140. algorithm: "sha256", // the algorithm of the hash - available algorithms depend on the OpenSSL version installed on the machine (on linux can be listed with "openssl list -digest-algorithms")
  141. digest: "hex", // the output format of the hash - can be "base64", "hex" or "latin1"
  142. },
  143. encodings: {
  144. gzip: true, // Whether or not Gzip encoding should be enabled for the documentation page
  145. deflate: true, // Whether or not Deflate encoding should be enabled for the documentation page
  146. brotli: true, // Whether or not Brotli encoding should be enabled for the documentation page
  147. },
  148. encodingPriority: [ // The priority of the encodings. Items with a lower array index (further to the left) have a higher priority
  149. "brotli", "gzip", "deflate"
  150. ],
  151. },
  152. errors: {
  153. errorLogDir: "./data/logs/", // path to the error log directory - needs trailing slash
  154. errorMessagesPath: "./data/errorMessages", // path to error messages file
  155. },
  156. lists: {
  157. blacklistPath: "./data/lists/ipBlacklist.json", // path to the IP blacklist
  158. whitelistPath: "./data/lists/ipWhitelist.json", // path to the IP whitelist
  159. consoleBlacklistPath: "./data/lists/consoleBlacklist.json", // path to the IP console blacklist
  160. },
  161. documentation: {
  162. dirPath: "./docs/", // path to the documentation directory - needs trailing slash
  163. compiledPath: "./docs/compiled/", // path to the compiled docs directory - needs trailing slash
  164. faviconPath: "./docs/static/favicon.ico", // path to the favicon.ico file - don't add trailing slash
  165. rawDirPath: "./docs/raw/", // path to the raw documentation files directory - needs trailing slash
  166. daemonInterval: 2, // interval (in seconds) at which the daemon checks for changes in the documentation directory
  167. errorPagePath: "./docs/raw/errorPage.html", // path to the error page
  168. codeFontFileName: "static/external/CascadiaCode_2108.26.ttf", // the name of the font file that is going to be used in code blocks - relative to the directory specified with the above property "dirPath"
  169. submissionForm: {
  170. dirPath: "./docs/raw/", // path to the submission form directory - needs trailing slash
  171. fileNames: {
  172. html: "submit.html", // name of the HTML file of the submission form - relative to the parameter "documentation.submissionForm.dirPath"
  173. js: "../static/submit.js", // name of the JS file of the submission form - relative to the parameter "documentation.submissionForm.dirPath"
  174. css: "../static/submit.css", // name of the CSS file of the submission form - relative to the parameter "documentation.submissionForm.dirPath"
  175. },
  176. },
  177. },
  178. endpoints: {
  179. dirPath: "./endpoints/", // path to the dir containing all the endpoint scripts
  180. ratelimitBlacklist: [ // calling an endpoint in this array will not count towards the rate limit counter
  181. "static",
  182. ],
  183. },
  184. colors: {
  185. success: col.green, // when request was successful
  186. error: col.red, // when request was errored
  187. ratelimit: col.magenta, // when request was rate limited
  188. docs: col.yellow, // when docs were requested
  189. blacklisted: bgc.red + col.yellow, // when a request IP is blacklisted
  190. docsrecompiled: bgc.yellow + col.blue, // when the docs were recompiled
  191. },
  192. analytics: {
  193. enabled: false, // whether or not the analytics module should be enabled
  194. dirPath: "./data/analytics/", // path to the analytics directory - needs trailing slash
  195. sqlTableName: "analytics", // name of the SQL table
  196. },
  197. sql: { // (login credentials are set in the .env file)
  198. host: "localhost", // IP address to the DB host - default for local device is "localhost"
  199. database: "jokeapi", // the name of the DB
  200. port: 3306, // the port of the DB - default is 3306
  201. },
  202. auth: {
  203. tokenListFile: "./data/tokens.json", // path to the token list file
  204. tokenHeaderName: "authorization", // the name of the token header (lower case)
  205. tokenValidHeader: "Token-Valid", // the name of the token validity response header (normal case, not lower case)
  206. daemonInterval: 20, // after how many seconds the auth tokens should be refreshed
  207. },
  208. languages: {
  209. langFilePath: "./data/languages.json", // file containing all language codes and corresponding language information
  210. defaultLanguage: "en", // default language (two character code, lowercase)
  211. translationsFile: "./data/translations.json", // translations file
  212. },
  213. tests: { // unit tests
  214. location: "./tests/", // folder where unit tests are located - requires trailing slash
  215. initPingInterval: 250, // in ms - interval between init pings (default: 250)
  216. }
  217. }
  218. module.exports = Object.freeze(settings); // use Object.freeze() to prevent modifications at runtime