Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ server.start({
});
```

You can configure the logging options as well via `logger`

```js
server.start({
logger: {
level: 'ALL',
appenders: [
{ type: 'console' }
]
},
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, just a couple more changes, then it's ready to merge! 🎉 . Should probably add an example here of using a logger default values.

```

We use the (https://github.com/nomiddlename/log4js-node/wiki/Connect-Logger)[log4js] connect logger. Learn more about the available options from their project.


## Global Install

Expand Down
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ var path = require('path')
var serveStatic = require('serve-static')
var serveStaticFile = require('connect-static-file')
var compression = require('compression')
var log4js = require('log4js')
var app = connect()

const PORT = 9000
const DIRECTORY = 'public'
const FILE = 'index.html'
const HOST = '0.0.0.0'
const LOGGEROPTIONS = {
level: 'ALL',
appenders: [ { type: 'console' } ]
}

exports.start = function (options, _onStarted) {
options = options || {}
Expand All @@ -20,16 +25,23 @@ exports.start = function (options, _onStarted) {
let directories = options.directories || [directory]
let file = options.file || FILE
let host = options.host || HOST
let loggerOptions = options.logger || LOGGEROPTIONS
let onStarted = _onStarted || function () {}

app.use(compression())

// First, check the file system
// configure logger
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably only use the logger if they provide a config for it (not default to all the time)

log4js.configure(loggerOptions)
const logger = log4js.getLogger()
logger.setLevel(loggerOptions.level)
app.use(log4js.connectLogger(logger, { level: log4js.levels[loggerOptions.level] }))

// check the file system
directories.forEach(function(directory) {
app.use(serveStatic(directory, { extensions: ['html'] }))
})

// Then, serve the fallback file
// serve the fallback file
app.use(serveStaticFile(path.join(directory, file)))

return app.listen(port, host, function (err) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"compression": "^1.1.0",
"connect": "^3.2.0",
"connect-static-file": "^1.1.2",
"log4js": "^1.1.0",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go ahead and lock the dependency here to the latest current version. (I locked the dependencies recently to avoid any unknown breaking changes)

"serve-static": "^1.6.2"
},
"devDependencies": {
Expand Down