mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
docs: update serverMiddleware
to add warning on function and make example esm (#3894)
* docs: update serverMiddleware to add warning on function and make example esm * Update packages/schema/src/config/_common.ts Co-authored-by: pooya parsa <pyapar@gmail.com>
This commit is contained in:
parent
dc1064f79a
commit
c7f4e3c709
@ -328,13 +328,15 @@ export default {
|
||||
* Server middleware are connect/express/h3-shaped functions that handle server-side requests. They
|
||||
* run on the server and before the Vue renderer.
|
||||
*
|
||||
* By adding entries to `serverMiddleware` you can register additional routes or modify `req`/`res`
|
||||
* objects without the need for an external server.
|
||||
* By adding entries to `serverMiddleware` you can register additional routes without the need
|
||||
* for an external server.
|
||||
*
|
||||
* You can pass a string, which can be the name of a node dependency or a path to a file. You
|
||||
* can also pass an object with `path` and `handler` keys. (`handler` can be a path or a
|
||||
* function.)
|
||||
*
|
||||
* @note If you pass a function directly, it will only run in development mode.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* serverMiddleware: [
|
||||
@ -342,7 +344,7 @@ export default {
|
||||
* 'redirect-ssl',
|
||||
* // Will register file from project server-middleware directory to handle /server-middleware/* requires
|
||||
* { path: '/server-middleware', handler: '~/server-middleware/index.js' },
|
||||
* // We can create custom instances too
|
||||
* // We can create custom instances too, but only in development mode, they are ignored for the production bundle.
|
||||
* { path: '/static2', handler: serveStatic(__dirname + '/static2') }
|
||||
* ]
|
||||
* ```
|
||||
@ -368,13 +370,14 @@ export default {
|
||||
* Alternatively, it can export a connect/express/h3-type app instance.
|
||||
* @example
|
||||
* ```js
|
||||
* const bodyParser = require('body-parser')
|
||||
* const app = require('express')()
|
||||
* import bodyParser from 'body-parser'
|
||||
* import createApp from 'express'
|
||||
* const app = createApp()
|
||||
* app.use(bodyParser.json())
|
||||
* app.all('/getJSON', (req, res) => {
|
||||
* res.json({ data: 'data' })
|
||||
* })
|
||||
* module.exports = app
|
||||
* export default app
|
||||
* ```
|
||||
*
|
||||
* Alternatively, instead of passing an array of `serverMiddleware`, you can pass an object
|
||||
|
Loading…
Reference in New Issue
Block a user