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:
Daniel Roe 2022-03-25 11:40:15 +00:00 committed by GitHub
parent dc1064f79a
commit c7f4e3c709
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -328,13 +328,15 @@ export default {
* Server middleware are connect/express/h3-shaped functions that handle server-side requests. They * Server middleware are connect/express/h3-shaped functions that handle server-side requests. They
* run on the server and before the Vue renderer. * run on the server and before the Vue renderer.
* *
* By adding entries to `serverMiddleware` you can register additional routes or modify `req`/`res` * By adding entries to `serverMiddleware` you can register additional routes without the need
* objects without the need for an external server. * 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 * 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 * can also pass an object with `path` and `handler` keys. (`handler` can be a path or a
* function.) * function.)
* *
* @note If you pass a function directly, it will only run in development mode.
*
* @example * @example
* ```js * ```js
* serverMiddleware: [ * serverMiddleware: [
@ -342,7 +344,7 @@ export default {
* 'redirect-ssl', * 'redirect-ssl',
* // Will register file from project server-middleware directory to handle /server-middleware/* requires * // Will register file from project server-middleware directory to handle /server-middleware/* requires
* { path: '/server-middleware', handler: '~/server-middleware/index.js' }, * { 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') } * { path: '/static2', handler: serveStatic(__dirname + '/static2') }
* ] * ]
* ``` * ```
@ -368,13 +370,14 @@ export default {
* Alternatively, it can export a connect/express/h3-type app instance. * Alternatively, it can export a connect/express/h3-type app instance.
* @example * @example
* ```js * ```js
* const bodyParser = require('body-parser') * import bodyParser from 'body-parser'
* const app = require('express')() * import createApp from 'express'
* const app = createApp()
* app.use(bodyParser.json()) * app.use(bodyParser.json())
* app.all('/getJSON', (req, res) => { * app.all('/getJSON', (req, res) => {
* res.json({ data: 'data' }) * res.json({ data: 'data' })
* }) * })
* module.exports = app * export default app
* ``` * ```
* *
* Alternatively, instead of passing an array of `serverMiddleware`, you can pass an object * Alternatively, instead of passing an array of `serverMiddleware`, you can pass an object