coserv
is a simple file server intended to be used primarily
while developing single page apps, or statically generated sites.
In includes:
Normally installation isn't required as it's included in the NPM packages for CodeOnly generated projects that need it.
eg: the CodeOnly SPA project uses coserv
automatically when running
npm run dev
or npm run prod
To manually install (use --save
or -g
as required)
npm install codeonlyjs/coserv
To run:
npx coserv
To run without installing
npx codeonlyjs/coserv
coserv
requires a file named coserv.config.js
in the current directory.
See the <dir>
command line option to change the current directory at
start up
The config file should have a default export that defines the configuration settings to use.
const config = {
port: 3000,
development: {
bundleFree: {
// Bundle free options here
},
livereload: {
options:
{
// Live reload options here
}
watch:
[
// Folders to watch here
]
}
},
production: {
// Production options here (same as development)
}
};
export default config;
The final configuration is determined by deeply merging:
coserv
's built-in default configurationdevelopment
or production
branches of the
configuration (or other branch as specified by NODE_ENV)To see the final merged configuration, use the --show-config
command line option.
The following shows the default configuration. You only need to specify options in your configuration file that differ from these:
{
port: 3000,
host: null,
development:
{
logging: "dev",
bundleFree: {
path: ".",
spa: true,
node_modules: "./node_modules",
inYaFace: true,
},
livereload: {
options: {
},
watch: [
".",
]
}
},
production:
{
logging: "combined",
bundleFree: {
path: "./dist",
spa: true,
}
}
}
Most of the settings in the configuration file match exactly those expected by the respective modules:
bundleFree
: See Bundle-free
livereload
: See Live Reload
options
- the options passed to livereload.createServer
watch
- the array passed to livereload.watch
logging
: See Morgan
The following coserv
specific options are also supported:
port
- the port to use (can be overridden by --port
)host
- the host name to use (can be overridden by --host
)The following command line options are supported:
--env:<env> Set NODE_ENV (typically development|production)
--dev Shortcut for --env:development
--prod Shortcut for --env:production
-p, --port:<port> Set server port
--host:<host> Set server host
--show-config Log final configuration
-v, --version Show version info
-h, --help Show this help
<dir> Change current working directory
For a complete example configuration file, see the config file used for this site:
https://github.com/codeonlyjs/website/blob/main/coserv.config.js