express: Update formatting

This commit is contained in:
Rico Sta. Cruz 2018-05-16 08:01:38 +08:00
parent b7f35db21d
commit a0f24f42d9
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
1 changed files with 74 additions and 44 deletions

View File

@ -5,6 +5,7 @@ category: JavaScript libraries
### Settings ### Settings
```js
app.set('x', 'yyy') app.set('x', 'yyy')
app.get('x') //=> 'yyy' app.get('x') //=> 'yyy'
@ -12,31 +13,42 @@ category: JavaScript libraries
app.disable('trust proxy') app.disable('trust proxy')
app.enabled('trust proxy') //=> true app.enabled('trust proxy') //=> true
```
### Env ### Env
```js
app.get('env') app.get('env')
```
### Config ### Config
```js
app.configure('production', function() { app.configure('production', function() {
app.set... app.set...
}); })
```
### Wares ### Wares
app.use(express.static(__dirname + '/public')); ```js
app.use(express.logger()); app.use(express.static(__dirname + '/public'))
app.use(express.logger())
```
### Helpers ### Helpers
```js
app.locals({ app.locals({
title: "MyApp", title: "MyApp",
}); })
```
## Request & response
### Request ### Request
```js
// GET /user/tj // GET /user/tj
req.path //=> "/user/tj" req.path //=> "/user/tj"
req.url //=> "/user/tj" req.url //=> "/user/tj"
@ -45,34 +57,52 @@ category: JavaScript libraries
req.params req.params
req.params.name //=> "tj" req.params.name //=> "tj"
req.params[0] req.params[0]
```
```js
// GET /search?q=tobi+ferret // GET /search?q=tobi+ferret
req.query.q // => "tobi ferret" req.query.q // => "tobi ferret"
```
```js
req.cookies req.cookies
```
```js
req.accepted req.accepted
[ { value: 'application/json', quality: 1, type: 'application', subtype: 'json' }, // [ { value: 'application/json', quality: 1, type: 'application', subtype: 'json' },
{ value: 'text/html', quality: 0.5, type: 'text',subtype: 'html' } ] // { value: 'text/html', quality: 0.5, type: 'text',subtype: 'html' } ]
```
```js
req.is('html') req.is('html')
req.is('text/html') req.is('text/html')
```
```js
req.headers req.headers
req.headers['host'] req.headers['host']
req.headers['user-agent'] req.headers['user-agent']
req.headers['accept-encoding'] req.headers['accept-encoding']
req.headers['accept-language'] req.headers['accept-language']
```
### Response
## Response ```js
res.redirect('/') res.redirect('/')
res.redirect(301, '/') res.redirect(301, '/')
```
```js
res.set('Content-Type', 'text/html') res.set('Content-Type', 'text/html')
```
```js
res.send('hi') res.send('hi')
res.send(200, 'hi') res.send(200, 'hi')
```
```js
res.json({ a: 2 }) res.json({ a: 2 })
```