示例#1
0
/**
 * Static server with enb make on demand
 */
if (!BEM.blocks['i-command'].get('no-static-proxy')) {
    var mime = require('mime');
    var cdir = process.cwd();
    var enbServerMiddleware = require('enb/lib/server/server-middleware');
    var TargetNotFoundError = require('enb/lib/errors/target-not-found-error');
    var builder = enbServerMiddleware.createBuilder({
        noLog: true
    });
    var fs = require('fs');
    var HttpError = BEM.blocks['i-errors'].HttpError;

    BEM.blocks['i-router'].define('GET', /\.\w+$/i, 'i-enb');

    BEM.decl('i-enb', null, {

        /**
         * @param  {String} path
         * @param  {String} mimeType
         * @return {Promise}
         */
        _checkAllowedFiles: function (path, mimeType) {
            if (mimeType === 'application/javascript') {
                if (path.match(/(priv|server)\.js$/)) {
                    return Vow.reject(new HttpError(404));
                }
            }
            return Vow.fulfill();
        },
示例#2
0
var express = require('express');
var enbServerMiddleware = require('enb/lib/server/server-middleware');
var dropRequireCache = require('enb/lib/fs/drop-require-cache');
var enbBuilder = enbServerMiddleware.createBuilder();

module.exports = {
    /**
     * Host for static files.
     */
    host: '/',

    /**
     * @returns {Object} Express application as middleware.
     */
    middleware: function () {
        return express.Router()
            .use(enbServerMiddleware.createMiddleware())
            .use('/blocks', express.static(__dirname + '/../../blocks'))
            .use('/node_modules', express.static(__dirname + '/../../node_modules'))
            .use('/test/client', express.static(__dirname + '/../../test/client'));
    },

    /**
     * @param {String} assetPath
     * @returns {Module} module
     */
    require: function (assetPath) {
        return enbBuilder(assetPath).then(function (fileName) {
            dropRequireCache(require, fileName);
            return require(fileName);
        });