# mdpress-plugin-serve
Serve generated files of your MdPress site locally.
# Installation
npm install -D mdpress-plugin-serve
# Usage
// .mdpress/config.js
module.exports = {
plugins: [
[
"mdpress-plugin-serve",
{
post: 1234,
staticOptions: {
dotfiles: "allow",
},
beforeServer(app, server) {
app.get("/path/to/my/custom", function (req, res) {
res.json({ custom: "response" });
});
},
},
],
],
};
# Configs
# commandName
- type:
string
- default:
'serve'
mdpress-plugin-serve will add a mdpress command. This option can be used to specify the command name.
# host
- type:
string
- default:
siteConfig.host || 'localhost'
Specify the host to use for the server.
# port
- type:
number
- default:
siteConfig.port || 8080
Specify the port to use for the server.
# notFoundPath
- type:
string
- default:
'404.html'
Path for "404 not found" page (relative to dest
path).
# staticOptions
- type:
object
- default:
{}
Options for serve-static.
# beforeServer
- type:
(app, server) => void | Promise<void>
- default:
undefined
Executed before the server accepts client information. Similar to MdPress's beforeDevServer option.
# afterServer
- type:
async (app, server) => void | Promise<void>
- default:
undefined
Executed after the server accepts client information. Similar to MdPress's afterDevServer option.
# CLI
After using this plugin, MdPress will add a serve
command. This command will created a server based on the generated files. It has the following options:
# --build
Execute mdpress build
before creating the server.
# --open
Open the browser when the server is ready.
# --host <host>
See host.
# --port <port>
See port.
::: tip
MdPress built-in command line options (such as --dest <dest>
, --cache [cache]
, --no-cache
) are also supported.
:::