Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow "connect-like" object to be passed to grunt-express as the "server" #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ app.use(function staticsPlaceholder(req, res, next) {
```

#### server
Type: `String`
Type: `String|Object`
Default: null

This option allows you to specify a path to a Node.js module that exports a "connect-like" object. Such object should have the following two functions:
This option allows you to specify a "connect-like" object. This can optionally be a path to a Node.js module that exports a such an object. Such object should have the following two functions:

1. `use(route, fn)` (https://github.com/senchalabs/connect/blob/master/lib/proto.js#L62)
2. `listen()` (https://github.com/senchalabs/connect/blob/master/lib/proto.js#L227)
Expand Down
25 changes: 15 additions & 10 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,22 @@ exports.runServer = function runServer(grunt, options) {

var server;
if (options.server) {
try {
server = require(path.resolve(options.server));
if (typeof server.listen !== 'function') {
grunt.fatal('Server should provide a function called "listen" that acts as http.Server.listen');
if (typeof options.server === 'string') {
try {
server = require(path.resolve(options.server));
} catch (e) {
var errorMessage = options.showStack ? '\n' + e.stack : e;
grunt.fatal('Server ["' + options.server + '"] - ' + errorMessage);
}
if (typeof server.use !== 'function') {
grunt.fatal('Server should provide a function called "use" that acts as connect.use');
}
} catch (e) {
var errorMessage = options.showStack ? '\n' + e.stack : e;
grunt.fatal('Server ["' + options.server + '"] - ' + errorMessage);
} else {
server = options.server;
}

if (typeof server.listen !== 'function') {
grunt.fatal('Server should provide a function called "listen" that acts as http.Server.listen');
}
if (typeof server.use !== 'function') {
grunt.fatal('Server should provide a function called "use" that acts as connect.use');
}
} else {
server = connect();
Expand Down