Config
DefineConfig
Create zely.config.js
or zely.config.ts
to define config.
- Default
ts
export default {};
export default {};
js
module.exports = {};
module.exports = {};
- Using
defineConfig()
ts
import { defineConfig } from 'zely/config';
export default defineConfig({
/* config */
});
import { defineConfig } from 'zely/config';
export default defineConfig({
/* config */
});
js
const { defineConfig } = require('zely/config');
module.exports = defineConfig({
/* config */
});
const { defineConfig } = require('zely/config');
module.exports = defineConfig({
/* config */
});
Types
base
- Type:
string
- Default:
.
Project root directory. (only relative path)
routes
- Type:
string
- Default:
/pages/
Directory where page files are located.
middlewares
- Type:
Array<Middleware>
Middlewares Array
ts
function example(req, res, next) {
req.message = 'Hello World';
next();
}
export default {
middlewares: [example],
};
function example(req, res, next) {
req.message = 'Hello World';
next();
}
export default {
middlewares: [example],
};
port
- Type:
number
- Default:
5050
Port
handler
- Type:
HandlerType
Custom Server Handler
ts
await Zely({
handler: (req, res, routes) => {
// ...
},
});
await Zely({
handler: (req, res, routes) => {
// ...
},
});
esbuild
- Type:
esbuild.BuildOptions
Esbuild build option.
plugins
- Type:
Plugin[]
TIP
reference: plugin
watch
- Type:
{enable: boolean; options: chokidar.WatchOptions;}
error
- Type:
(req: IncomingMessage, res: ServerResponse) => void | Promise<void>;
allowAutoMiddlewares
- Type:
boolean
TIP
reference: auto middleware
middlewareDirectory
- Type:
string
server
ts
interface Config {
// ...
server?: {
middlewareMode?: boolean;
// osik server options
osik?: ServerOptions;
// if you enable `keepCache`, zely will not remove cache directory when server starts.
keepCache?: boolean;
};
}
interface Config {
// ...
server?: {
middlewareMode?: boolean;
// osik server options
osik?: ServerOptions;
// if you enable `keepCache`, zely will not remove cache directory when server starts.
keepCache?: boolean;
};
}
useBrackets
If you enable useBrackets
, you can set routes using brackets like /[id]/index.ts
.