mirror of
https://github.com/expressjs/expressjs.com.git
synced 2026-02-21 19:41:33 +00:00
docs: update documentation for res.type() (#1783)
Signed-off-by: Dustin Popp <dustinpopp@ibm.com>
This commit is contained in:
@@ -14,3 +14,5 @@ res.type('application/json')
|
||||
res.type('png')
|
||||
// => 'image/png'
|
||||
```
|
||||
|
||||
Aliased as `res.contentType(type)`.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<h3 id='res.type'>res.type(type)</h3>
|
||||
|
||||
Sets the `Content-Type` HTTP header to the MIME type as determined by the specified `type`. If `type` contains the "/" character, then it sets the `Content-Type` to the exact value of `type`, otherwise it is assumed to be a file extension and the MIME type is looked up in a mapping using the `express.static.mime.lookup()` method.
|
||||
Sets the `Content-Type` HTTP header to the MIME type as determined by the specified `type`. If `type` contains the "/" character, then it sets the `Content-Type` to the exact value of `type`, otherwise it is assumed to be a file extension and the MIME type is looked up using the `contentType()` method of the `mime-types` package.
|
||||
|
||||
```js
|
||||
res.type('.html') // => 'text/html'
|
||||
@@ -9,3 +9,5 @@ res.type('json') // => 'application/json'
|
||||
res.type('application/json') // => 'application/json'
|
||||
res.type('png') // => image/png:
|
||||
```
|
||||
|
||||
Aliased as `res.contentType(type)`.
|
||||
|
||||
@@ -37,6 +37,7 @@ You can then run your automated tests to see what fails, and fix problems accord
|
||||
<li><a href="#res.send.body">res.send(body, status)</a></li>
|
||||
<li><a href="#res.send.status">res.send(status)</a></li>
|
||||
<li><a href="#res.sendfile">res.sendfile()</a></li>
|
||||
<li><a href="#express.static.mime">express.static.mime</a></li>
|
||||
</ul>
|
||||
|
||||
**Changed**
|
||||
@@ -262,6 +263,20 @@ app.get('/user', (req, res) => {
|
||||
})
|
||||
```
|
||||
|
||||
<h4 id="express.static.mime">express.static.mime</h4>
|
||||
|
||||
In Express 5, `mime` is no longer an exported property of the `static` field.
|
||||
Use the [`mime-types` package](https://github.com/jshttp/mime-types) to work with MIME type values.
|
||||
|
||||
```js
|
||||
// v4
|
||||
express.static.mime.lookup('json')
|
||||
|
||||
// v5
|
||||
const mime = require('mime-types')
|
||||
mime.lookup('json')
|
||||
```
|
||||
|
||||
<h3>Changed</h3>
|
||||
|
||||
<h4 id="path-syntax">Path route matching syntax</h4>
|
||||
|
||||
Reference in New Issue
Block a user