Skip to content

Commit

Permalink
Remove serveStatic and use serveAsset in balancer.
Browse files Browse the repository at this point in the history
  • Loading branch information
lsm committed Oct 26, 2015
1 parent 3623c4c commit 02950d4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
9 changes: 3 additions & 6 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,10 @@ MicroMonoServer.prototype.startBalancer = function(app) {
.then(function() {
return asset.configJSPM()
})

if (asset.publicURL && asset.publicPath) {
// Serve local asset files.
promise = promise.then(function() {
framework.serveStatic(asset.publicURL, asset.publicPath)
.then(function() {
// Serve local asset files.
framework.serveAsset(asset)
})
}

return promise
.then(function() {
Expand Down
29 changes: 16 additions & 13 deletions lib/web/framework/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ ExpressAdapter.prototype.setApp = function(app) {
this.app = app
}

ExpressAdapter.prototype.serveStatic = function(publicUrl, publicPath) {
debug('serve static files from path \n"%s"\n under url "%s"', publicPath, publicUrl)
this.aapp.use(publicUrl, express.static(publicPath))
}

ExpressAdapter.prototype.startServer = function(port, host, service) {
var mainApp
var app = this.getApp()
Expand Down Expand Up @@ -145,16 +140,20 @@ ExpressAdapter.prototype.attachRoute = function(route, router, service) {
/**
* Serve the static asset files accroding to service settings.
*
* @param {Asset} asset The instance of asset.
* @param {Router} router The instance of Router.
* @param {Service} service The service instance.
* @param {Asset} asset The instance of asset.
* @param {Router} [router] The instance of Router.
* @param {Service} [service] The service instance.
* @return {ExpressAdapter} The instance of this adpater.
*/
ExpressAdapter.prototype.serveAsset = function(asset, router, service) {
var app = this.aapp
var publicURL = asset.getPublicURL()

if (service.isRemote()) {
if (!publicURL) {
return this
}

if (service && service.isRemote()) {
// proxy requests for static asset
var assetHandler = router.getProxyHandler()
publicURL.forEach(function(url) {
Expand All @@ -164,10 +163,14 @@ ExpressAdapter.prototype.serveAsset = function(asset, router, service) {
})
} else {
var publicPath = asset.getPublicPath()
publicURL.forEach(function(url) {
debug('[%s] serve local static asset at "%s" with url "%s"', service.name, url, publicPath)
app.use(url, express.static(publicPath))
})
if (publicPath) {
var name = service && service.name || ''
name = name && '[' + name + '] '
publicURL.forEach(function(url) {
debug(name + 'serve static files from "%s" for url "%s"', publicPath, url)
app.use(url, express.static(publicPath))
})
}
}

return this
Expand Down

0 comments on commit 02950d4

Please sign in to comment.