v0.4.0-beta.1 - 2018-04-14
Pre-release❗ This release contains breaking changes (see 0.4.0 Migrating)
❗ Upgrade engine: 'node >= 8.0.0'
Added
-
✨ New feature:
Catcher(TODO: example) -
✨ New feature:
plugin-support(see 0.4.0 Plugins) -
New built-in plugin:
ignore-paths(For Router) -
New built-in plugin:
debug(For Router) -
New Router option
build.pluginswhich allows custom transform plugins for BuilderFor example:
app.use(dynapi({ router: { build: { plugins: ['@babel/plugin-proposal-pipeline-operator'] } } }))
which allows you using
pipeline-operatorin your routes.
Changed
- ❗ Adjustment options of
factoryand almost internal classes (see 0.4.0 Overview)
Deprecated
- Deprecate
export.ignoreproperty of Responsers, Middlewares and Parameters
Internal
-
Remove unused code
-
Change relations between classes for lower coupling
-
Refactor the whole rendering algorithm
Details
Overview
For planning in the future, we decided to separate options from
factoryand other
internal classes to reduce relies on each other.
*Now dynapi has no default router setted. To work like before, you can just use:
const factoryOptions = {
routers: [], // If you have more than 1 router, list them in it
router: {
root: '/', // Just like `app.use()`. Default '/'
rootdir: process.cwd(), <-------. // Default `process.cwd()`
srcdir: './server', <---------|-. // Required. Relative from `rootdir`
routesdir: './api', <----------|-|-. // Required. Relative from `srcdir`
prefixes: { ... }, <--------. | | |
aliases: [ ... ], <-------. | | | |
methods: [ ... ], <------. | | | | |
plugins: [ | | | | | |
['ignore-path', [...]] <|-|-|--|-|-|--.
], | | | | | | |
ignore: [...], <---------|-|-|--|-|-|--.
}, | | | | | | |
// rootDir: process.cwd(), -|-|-|--' | | |
// srcDir: './server', ---|-|-|----' | |
// routesDir: './api', ----|-|-|------' |
// symbol: { ... }, -----|-|-' |
// aliases: [ ... ], ------|-' |
// methods: [ ... ], -------' |
defaultTimeout: 800, <----. |
// responseTimeout: 800 --' |
// ignorePaths: [...] -------------------'
}Plugins support
Since we think it (dynapi) should only do one simple thing: Route rendering, we moved some
features that they're not always necessary from the core toplugins, to keep the core purely.
These removed features were rewrote as multiple plugins and they're still shipped with dynapi
as built-in plugins.
PLugins can be installed in two ways:
Use plugins options
app.use('/', dynapi({
plugins: [
['serve-static', 'public/ftp', { index: ['index.html', 'index.htm'] }]
]
}))Use alias (built-in plugins only)
app.use('/', dynapi({
statics: [
['public/ftp', { root: '/ftp', index: ['index.html', 'index.htm'] }],
['public/images', { root: '/images' }]
]
}))Plugin ignore-paths
Prevent some path pass through dynapi.
- Type:
Array<String|RegExp>
Usage:
app.use('/', dynapi({
router: {
...,
ignore: ['/__webpack_hmr']
}
}))
// or
app.use('/', dynapi({
router: {
...,
plugins: [
['ignore-paths', ['/__webpack_hmr']]
]
}
}))Migrating from 0.3.7
1. Rename options
*Pay attention to the case
app.use(dynapi({
router: {
rootdir, <----------.
srcdir, <-----------|-. // Use '.' if no value
routesdir, <--------|-|-. // Use './api' if no value
prefixes, <--. | | |
aliases, <---|-. | | |
methods, <---|-|-. | | |
ignore <-----|-|-|--|-|-|--.
}, | | | | | | |
// rootDir, ----|-|-|--' | | |
// srcDir, -----|-|-|----' | |
// routesDir, --|-|-|------' |
// symbol, ---' | | |
// aliases, ------' | |
// methods, --------' |
defaultTimeout, <-----. |
// responseTimeout, --' |
// ignorePaths ---------------'
}))