Add ability to log requests
This commit is contained in:
parent
2d14e5fd33
commit
3ae120b3ba
38
README.md
38
README.md
@ -134,17 +134,37 @@ unix domain socket.
|
|||||||
|
|
||||||
To access the server, go to http://localhost:3000 (or another port).
|
To access the server, go to http://localhost:3000 (or another port).
|
||||||
|
|
||||||
# Testing
|
# Logging
|
||||||
|
|
||||||
|
By default, Peer Calls server will log only basic information. Client-side
|
||||||
|
logging is disabled by default.
|
||||||
|
|
||||||
|
Server-side logs can be configured via the `DEBUG` environment variable. Setting
|
||||||
|
it to `peercalls,peercalls:*` will enable all server-side logging:
|
||||||
|
|
||||||
|
- `DEBUG=peercalls,peercalls:* npm run start:server`
|
||||||
|
|
||||||
|
Client-side logs can be configured via `localStorage.DEBUG` and
|
||||||
|
`localStorage.LOG` variables:
|
||||||
|
|
||||||
|
- Setting `localStorage.LOG=1` enables logging of Redux actions and state
|
||||||
|
changes
|
||||||
|
- Setting `localStorage.DEBUG=peercalls,peercalls:*` enables all other
|
||||||
|
client-side logging
|
||||||
|
|
||||||
|
# Development
|
||||||
|
|
||||||
|
Below are some common NPM scripts that are used for development:
|
||||||
|
|
||||||
```bash
|
|
||||||
npm install
|
|
||||||
npm test
|
|
||||||
```
|
```
|
||||||
|
npm start start the precompiled server.
|
||||||
To run all tests and build production artifacts, run:
|
npm run build build all client-side resources.
|
||||||
|
npm run start:server start and compile server-side TypeScript on the fly,
|
||||||
```bash
|
restarts the server when the resources change.
|
||||||
npm run ci
|
npm run start:watch start the server, and recompile client-side resources
|
||||||
|
when the sources change.
|
||||||
|
npm test run all tests.
|
||||||
|
npm run ci run all linting, tests and build the client-side
|
||||||
```
|
```
|
||||||
|
|
||||||
# Browser Support
|
# Browser Support
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import index from './routes/index'
|
|||||||
import dot from 'express-dot-engine'
|
import dot from 'express-dot-engine'
|
||||||
|
|
||||||
const debug = _debug('peercalls')
|
const debug = _debug('peercalls')
|
||||||
|
const logRequest = _debug('peercalls:requests')
|
||||||
|
|
||||||
const BASE_URL: string = config.baseUrl
|
const BASE_URL: string = config.baseUrl
|
||||||
const SOCKET_URL = `${BASE_URL}/ws`
|
const SOCKET_URL = `${BASE_URL}/ws`
|
||||||
@ -29,6 +30,15 @@ app.engine('html', dot.__express)
|
|||||||
app.set('view engine', 'html')
|
app.set('view engine', 'html')
|
||||||
app.set('views', path.join(__dirname, '../../views'))
|
app.set('views', path.join(__dirname, '../../views'))
|
||||||
|
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
const start = Date.now()
|
||||||
|
res.on('finish', () => {
|
||||||
|
const duration = Date.now() - start
|
||||||
|
logRequest('%s %s %sms', req.method, req.originalUrl, duration)
|
||||||
|
})
|
||||||
|
next()
|
||||||
|
})
|
||||||
|
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
router.use('/res', express.static(path.join(__dirname, '../../res')))
|
router.use('/res', express.static(path.join(__dirname, '../../res')))
|
||||||
router.use('/static', express.static(path.join(__dirname, '../../build')))
|
router.use('/static', express.static(path.join(__dirname, '../../build')))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user