Skip to content

Commit

Permalink
add string support
Browse files Browse the repository at this point in the history
  • Loading branch information
leeluolee committed Dec 11, 2014
1 parent 9877fbf commit efde5ec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
28 changes: 19 additions & 9 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,14 @@ puer = module.exports = (options = {}) ->

if !options.proxy
addon app, options for own key, addon of helper.requireFolder path.join __dirname, "./addons"
app.use express.static options.dir
# config express



if options.addon
addon = name: path.resolve __dirname, options.addon


#TODO
restRoute = ()->
# change the cache routes
Expand All @@ -152,15 +154,25 @@ puer = module.exports = (options = {}) ->
delete require.cache[addon.name];
addon.routes = require addon.name;

for own path, callback of addon.routes
tmp = path.split /\s+/
for own pt, callback of addon.routes
tmp = pt.split /\s+/
if tmp.length > 1
path = tmp[1]
pt = tmp[1]
method = tmp[0]
else
path = tmp[0]
pt = tmp[0]
method = 'GET'
addon.router.route(method, path, callback)
if typeof callback is "string"
callback = do (callback)->
return (req, res, next)->
fs.readFile path.join( path.dirname(options.addon), callback), 'utf8', (err, content)->
if not err
res.send content
else
next()


addon.router.route(method, pt, callback)
helper.log("addon update !!!" + addon.name)
catch e
helper.log(e.message, "error")
Expand All @@ -186,9 +198,7 @@ puer = module.exports = (options = {}) ->



if not options.proxy
app.use express.static options.dir
else
if options.proxy
proxy.on 'proxyRes', (proxyRes, req, res, options)->

app.use (req, res, next)->
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/css/style.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
body {
padding: 30px;
background-color: #fff;
background-color: #aaa;
font: 21px "Lucida Grande", Helvetica, Arial, sans-serif;
}

Expand Down
1 change: 1 addition & 0 deletions test/route.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
"GET /home2/**": "fixtures/index.html",
"GET /home/code/:id": function(req, res, next){

},
Expand Down

0 comments on commit efde5ec

Please sign in to comment.