mirror of
https://github.com/SunRed/haste-server.git
synced 2024-11-23 09:50:17 +01:00
Config rewrite
This commit is contained in:
parent
e4eeec3d27
commit
daabcf7dcd
6 changed files with 141 additions and 123 deletions
|
@ -1,2 +1,3 @@
|
|||
**/*.min.js
|
||||
config.js
|
||||
example.config.js
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -8,3 +8,4 @@ data
|
|||
|
||||
npm-debug.log
|
||||
static/*.min.js
|
||||
config.js
|
|
@ -40,7 +40,7 @@ STDOUT. Check the README there for more details and usages.
|
|||
* `keyLength` - the length of the keys to user (default 10)
|
||||
* `maxLength` - maximum length of a paste (default 400000)
|
||||
* `staticMaxAge` - max age for static assets (86400)
|
||||
* `recompressStaticAssets` - whether or not to compile static js assets (true)
|
||||
* `compressStaticAssets` - whether or not to compile static js assets (true)
|
||||
* `documents` - static documents to serve (ex: http://hastebin.com/about.md)
|
||||
in addition to static assets. These will never expire.
|
||||
* `storage` - storage options (see below)
|
||||
|
|
31
config.js
31
config.js
|
@ -1,31 +0,0 @@
|
|||
module.exports = {
|
||||
"host": "127.0.0.1",
|
||||
"port": 4200,
|
||||
|
||||
"keyLength": 10,
|
||||
"maxLength": 400000,
|
||||
|
||||
"staticMaxAge": 60 * 60 * 24,
|
||||
|
||||
"recompressStaticAssets": true,
|
||||
|
||||
"logging": [], //re-add this feature later
|
||||
|
||||
"keyGenerator": {
|
||||
"type": "phonetic"
|
||||
},
|
||||
|
||||
"rateLimits": {
|
||||
"windowMs": 60 * 60 * 1000,
|
||||
"max": 500
|
||||
},
|
||||
|
||||
"storage": {
|
||||
"type": "file",
|
||||
"path": "./data"
|
||||
},
|
||||
|
||||
"documents": {
|
||||
"about": "./about.md"
|
||||
}
|
||||
}
|
48
example.config.js
Normal file
48
example.config.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
module.exports = {
|
||||
//address and port to which server will bind, host can also be a hostname
|
||||
"host": "127.0.0.1",
|
||||
"port": 7777,
|
||||
|
||||
//length of random characters in link that's generated on document save
|
||||
"keyLength": 10,
|
||||
//max allowed paste length - 0 for unlimited
|
||||
"maxLength": 400000,
|
||||
|
||||
//algorithm used to generate random characters
|
||||
//see docs/generators.md for more information
|
||||
"keyGenerator": {
|
||||
"type": "phonetic"
|
||||
},
|
||||
|
||||
//max age for static website assets
|
||||
"staticMaxAge": 60 * 60 * 24,
|
||||
|
||||
//whether or not to minify static js scripts which load faster for end-users
|
||||
"compressStaticAssets": true,
|
||||
|
||||
//TODO: re-add more options to logging
|
||||
//logging preferences
|
||||
"logging": {
|
||||
//can be one of: error, warn, info, http, verbose, debug, silly
|
||||
"level": "info"
|
||||
},
|
||||
|
||||
//rate limits for requests, handled by express-rate-limit
|
||||
//options can be found here: https://github.com/nfriedly/express-rate-limit/blob/master/lib/express-rate-limit.js#L7-L14
|
||||
"rateLimits": {
|
||||
"windowMs": 30 * 60 * 1000,
|
||||
"max": 250
|
||||
},
|
||||
|
||||
//storage system used for storing saved haste documents
|
||||
//see docs/storage.md for more information
|
||||
"storage": {
|
||||
"type": "file",
|
||||
"path": "./data"
|
||||
},
|
||||
|
||||
//static documents that will never expire ("name": "path")
|
||||
"documents": {
|
||||
"about": "./about.md"
|
||||
}
|
||||
};
|
|
@ -1,5 +1,5 @@
|
|||
const fs = require('fs');
|
||||
const winston = require('winston');
|
||||
const fs = require('fs');
|
||||
const minify = require('babel-minify');
|
||||
const st = require('st');
|
||||
const app = require('express')();
|
||||
|
@ -11,9 +11,8 @@ const HasteUtils = require('./lib/util');
|
|||
const utils = new HasteUtils();
|
||||
|
||||
//set up logger
|
||||
//only Console for now, gotta utilize config.json in the future
|
||||
winston.add(new winston.transports.Console({
|
||||
level: 'silly',
|
||||
level: config.logging.level,
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize(),
|
||||
winston.format.printf(info => `${info.level}: ${info.message} ${utils.stringifyJSONMessagetoLogs(info)}`)
|
||||
|
@ -46,7 +45,7 @@ else {
|
|||
}
|
||||
|
||||
//compress static javascript assets
|
||||
if (config.recompressStaticAssets){
|
||||
if (config.compressStaticAssets){
|
||||
let files = fs.readdirSync('./static');
|
||||
//https://regex101.com/r/5cJagJ/2
|
||||
for (const file of files){
|
||||
|
|
Loading…
Reference in a new issue