Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from Kanaye/blocks.middleware
Added Blocks.middleware...
- Loading branch information
Showing
7 changed files
with
94 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,49 @@ | ||
define([ | ||
'../core', | ||
'./Server', | ||
], function (blocks, Server) { | ||
'./Middleware' | ||
], function (blocks, Server, Middleware) { | ||
blocks.server = function (options) { | ||
return new Server(options); | ||
}; | ||
|
||
blocks.static = function (options) { | ||
|
||
|
||
}; | ||
|
||
blocks.middleware = function (options) { | ||
var express = require('express'); | ||
var path = require('path'); | ||
// the real middleware | ||
var middleware; | ||
// array of middlewares to return | ||
var middlewares = []; | ||
|
||
var defaults = { | ||
// Should the files in static get delivered | ||
deliverStatics: true, | ||
baseTag: true | ||
}; | ||
|
||
if (blocks.isString(options)) { | ||
options = { | ||
static: options | ||
}; | ||
} | ||
|
||
options = blocks.extend({}, Middleware.Defaults, defaults, options); | ||
middleware = new Middleware(options); | ||
|
||
if (options.deliverStatics) { | ||
// express.static is required as the frontend app needs it's files | ||
middlewares.push(express.static(path.resolve(options.static), { | ||
index: false | ||
})); | ||
} | ||
|
||
middlewares.push(blocks.bind(middleware.tryServePage, middleware)); | ||
|
||
// returning array of express middlewares that express will call in that order | ||
return middlewares; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters