A web server for developers using duo
$ sudo npm -g install duo-serve
Usage: duo-serve [options] <entries...>
Options:
-h, --help output usage information
-b, --body <path> Path to file to use as content for page
-c, --copy Turns on copy instead of symlink
-g, --global <name> Export as a global with the given name
-h, --html <path> Path to custom handlebars template for page
-p, --port <number> Set the server port number
-r, --root <path> Set the duo root dir
-t, --title <title> Set the page title
-T, --token <token> Set the GitHub API token (default uses ~/.netrc)
-u, --use <plugins> Use npm modules or local files as plugins
var serve = require('duo-serve');
var handlebars = require('duo-handlebars');
serve(process.cwd())
.title('My Duo Module')
.entry('index.js')
.entry('index.css')
.use(handlebars())
.listen(3000);
Creates a new instance (with or without new
) of a duo server. The root
parameter will set the root used by duo. (defaults to process.cwd()
)
Gets/sets the string content of the <body>
tag on the generated HTML page.
Gets/sets the boolean value to be passed into Duo#copy()
.
Adds an entry file (relative to the configured root
) that will be processed
by duo and served to the generated HTML page.
The file
argument can also be an array of filenames.
Gets/sets the path to the image file to be used as the favicon. By default,
this will use the duo triangle logo. Passing a string path here will override
that, and false
will disable the favicon middleware altogether.
Gets/sets the name of the global variable that duo will use when processing the given entry files. (only works with a single JS entry file)
Gets/sets the path to the Handlebars template that is used to generate the HTML page.
Generates an express app using Server#server()
and passes the arguments to
it's listen()
method. This method will return the express app.
Gets/sets the argument to be passed to the
morgan middleware. The default value
is "dev", but passing false
explicitly will disable logging.
Gets/sets the root directory that duo uses for processing.
A factory method for an express server matching all the available configuration. Use this method when you need to augment the express app any further.
Gets/sets the title of the generated HTML page.
Gets/sets the GitHub API token that duo will use.
Adds a duo plugin that will be used when processing the entry files.
To start, the generated HTML should be sufficient. However, if you want to use
custom HTML, you are able to do so via the html
and body
options.
body
covers the contents of the <body>
tag only, which allows you to
simply add a few tags to operate on.
If you need a fully custom page to begin with, use html
, which overrides
the default template used by duo-serve. The default template looks like:
<!DOCTYPE html>
<html>
<head>
<title>{{title}}</title>
{{#each css}}
<link rel="stylesheet" type="text/css" href="/build/{{this}}">
{{/each}}
</head>
<body>
{{{body}}}
{{#each js}}
<script src="/build/{{this}}"></script>
{{/each}}
</body>
</html>
title
the title to be used for the page (defaults to "duo-serve")css
an array of css entry files (eg:[ "index.css" ]
)body
the contents of the file specified by--body
js
an array of js entry files (eg:[ "index.js" ]
)
- Entry files are prefixed by
/build/
, so don't forget that when outputting the<link>
and<script>
tags. - Body is raw HTML, so don't forget the triple-curlies (
{{{...}}}
)