diff --git a/.gitignore b/.gitignore index fd4f2b0..22d59e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules .DS_Store +.idea diff --git a/README.md b/README.md index 1391d18..2385d0e 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,32 @@ var server = flo( ); ``` +or integrate with exist server instance: + +``` +var express = require('express'), + app = express(), + http = require("http"), + server = http.createServer(app), + fs = require('fs') + +flo(PATH_TO_DIR,{ + server:server, + glob:[ + '**/*.css', + '**/*.html', + '**/*.jade' + ]},function( filePath, callback){ + callback({ + resourceURL : resourceURL, + contents : fs.readFileSync(path.join(root,filePath)), + update : function( _window,_resourceURL){ + } + }) + } + }) +``` + `flo` takes the following arguments. * `sourceDirToWatch`: absolute or relative path to the directory to watch that contains the source code that will be built. diff --git a/lib/flo.js b/lib/flo.js index b91594b..9a8a831 100644 --- a/lib/flo.js +++ b/lib/flo.js @@ -68,12 +68,13 @@ var DELAY = 200; * @private */ -function Flo(dir, options, callback) { +function Flo( dir, options, callback) { this.log = logger(options.verbose, 'Flo'); this.dir = dir; this.realpathdir = fs.realpathSync(dir); this.resolver = callback; this.server = new Server({ + server : options.server || null, port: options.port, host: options.host, log: logger(options.verbose, 'Server') diff --git a/lib/server.js b/lib/server.js index 232d371..d5cbdea 100644 --- a/lib/server.js +++ b/lib/server.js @@ -24,11 +24,11 @@ module.exports = Server; function Server(options) { this.log = options.log || function() {}; - this.httpServer = http.createServer(function(req, res) { + this.httpServer = options.server || http.createServer(function(req, res) { res.writeHead(404); res.end(); }); - this.httpServer.listen(options.port); + !options.server && this.httpServer.listen(options.port); this.wsServer = new WSS({ httpServer: this.httpServer, autoAcceptConnections: false diff --git a/package.json b/package.json index e6d1bde..dc626f5 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { - "name": "fb-flo", + "name": "fb-flo-extra", "version": "0.3.1", "description": "Modify running web apps without reloading", "repository": { "type": "git", - "url": "git@github.com:facebook/fb-flo.git" + "url": "git@github.com:sskyy/fb-flo.git" }, "main": "index.js", "scripts": {