Skip to content

Commit

Permalink
Added blocks.middleware.
Browse files Browse the repository at this point in the history
As discussed in astoilkov#95.
  • Loading branch information
Joscha Rohmann committed Dec 9, 2015
1 parent 9bd1f1d commit 42818cf
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/node/methods.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
define([
'../core',
'./Server',
], function (blocks, Server) {
'./Middleware'
], function (blocks, Server, Middleware) {
blocks.server = function (options) {
return new Server(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 = [];

options = blocks.extend({}, Middleware.Defaults, options);
middleware = new Middleware(options);

// 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;
};

blocks.static = function (options) {

};
Expand Down

0 comments on commit 42818cf

Please sign in to comment.