From c7f4e3c709e89041a15f37c82f278947f5a2c00d Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 25 Mar 2022 11:40:15 +0000 Subject: [PATCH] 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 --- packages/schema/src/config/_common.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/schema/src/config/_common.ts b/packages/schema/src/config/_common.ts index 57e314247a..c9d2f70f03 100644 --- a/packages/schema/src/config/_common.ts +++ b/packages/schema/src/config/_common.ts @@ -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