Skip to content

Commit

Permalink
(add) options to static assets
Browse files Browse the repository at this point in the history
  • Loading branch information
jstty committed Jan 15, 2017
1 parent 8387b32 commit 928cb3c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 32 deletions.
6 changes: 3 additions & 3 deletions legacy/http.framework.express.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ HttpFrameworkExpress.prototype.addMethodFunction = function (method, middlewareL
this._app[method](routeStr, handler);
};

HttpFrameworkExpress.prototype.addStaticDir = function (staticDir, staticRoute) {
HttpFrameworkExpress.prototype.addStaticDir = function (staticDir, staticRoute, staticOptions) {
if (staticRoute) {
return this._app.use(staticRoute, express.static(staticDir));
return this._app.use(staticRoute, express.static(staticDir, staticOptions));
} else {
return this._app.use(express.static(staticDir));
return this._app.use(express.static(staticDir, staticOptions));
}
};

Expand Down
31 changes: 19 additions & 12 deletions legacy/service.middleware/defaultRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,29 @@ var DefaultRoutes = function (_ServiceMiddleware) {
}, {
key: '_addStaticRoute',
value: function _addStaticRoute(service, staticContent, route) {
var staticOptions = {};
if (!_.isArray(staticContent) && _.isObject(staticContent)) {
var staticRoute = staticContent;

if (staticRoute.hasOwnProperty('from') && staticRoute.hasOwnProperty('to')) {
if (staticRoute.hasOwnProperty('from')) {
staticContent = staticRoute.from;
}
if (staticRoute.hasOwnProperty('to')) {
route = staticRoute.to;
} else {
if (staticRoute.hasOwnProperty('root')) {
service.directory.service = staticRoute.root;
}
if (staticRoute.hasOwnProperty('cache')) {
// TODO
}
if (staticRoute.hasOwnProperty('list')) {
staticContent = staticRoute.list;
}
}
if (staticRoute.hasOwnProperty('root')) {
service.directory.service = staticRoute.root;
}
if (staticRoute.hasOwnProperty('cache')) {}
// TODO

// this oversides "from"
if (staticRoute.hasOwnProperty('list')) {
staticContent = staticRoute.list;
}

if (staticRoute.hasOwnProperty('options') && _.isObject(staticRoute.options)) {
staticOptions = staticRoute.options;
}
}

Expand All @@ -177,7 +184,7 @@ var DefaultRoutes = function (_ServiceMiddleware) {
// logger.log("Adding Static Dir Content -", staticContent);
logger.log('Static Dir Route:', staticContent, '->', route || '/');

this._httpFramework.addStaticDir(staticContent, route);
this._httpFramework.addStaticDir(staticContent, route, staticOptions);
return true;
} else {
// logger.log("Adding Static File -", staticContent);
Expand Down
6 changes: 3 additions & 3 deletions lib/http.framework.express.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ HttpFrameworkExpress.prototype.addMethodFunction = function (method, middlewareL
this._app[ method ](routeStr, handler);
};

HttpFrameworkExpress.prototype.addStaticDir = function (staticDir, staticRoute) {
HttpFrameworkExpress.prototype.addStaticDir = function (staticDir, staticRoute, staticOptions) {
if (staticRoute) {
return this._app.use(staticRoute, express.static(staticDir));
return this._app.use(staticRoute, express.static(staticDir, staticOptions));
}
else {
return this._app.use(express.static(staticDir));
return this._app.use(express.static(staticDir, staticOptions));
}
};

Expand Down
31 changes: 18 additions & 13 deletions lib/service.middleware/defaultRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,30 @@ class DefaultRoutes extends ServiceMiddleware {
* @private
*/
_addStaticRoute (service, staticContent, route) {
var staticOptions = {};
if (!_.isArray(staticContent) &&
_.isObject(staticContent)) {
var staticRoute = staticContent;

if (staticRoute.hasOwnProperty('from') &&
staticRoute.hasOwnProperty('to')) {
if (staticRoute.hasOwnProperty('from')) {
staticContent = staticRoute.from;
}
if (staticRoute.hasOwnProperty('to')) {
route = staticRoute.to;
}
else {
if (staticRoute.hasOwnProperty('root')) {
service.directory.service = staticRoute.root;
}
if (staticRoute.hasOwnProperty('cache')) {
// TODO
}
if (staticRoute.hasOwnProperty('list')) {
staticContent = staticRoute.list;
}
if (staticRoute.hasOwnProperty('root')) {
service.directory.service = staticRoute.root;
}
if (staticRoute.hasOwnProperty('cache')) {
// TODO
}
// this oversides "from"
if (staticRoute.hasOwnProperty('list')) {
staticContent = staticRoute.list;
}

if (staticRoute.hasOwnProperty('options') && _.isObject(staticRoute.options)) {
staticOptions = staticRoute.options;
}
}

Expand All @@ -139,7 +144,7 @@ class DefaultRoutes extends ServiceMiddleware {
// logger.log("Adding Static Dir Content -", staticContent);
logger.log('Static Dir Route:', staticContent, '->', route || '/');

this._httpFramework.addStaticDir(staticContent, route);
this._httpFramework.addStaticDir(staticContent, route, staticOptions);
return true;
}
else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hyper.io",
"version": "0.7.1",
"version": "0.7.2",
"description": "MicroServices so fast they've gone plaid!",
"homepage": "https://github.com/jstty/hyper.io#readme",
"keywords": [
Expand Down

0 comments on commit 928cb3c

Please sign in to comment.