lime-static
Version:
Static file server for node.js REST servers using OWIN-JS framework for Project limerun
60 lines (51 loc) • 1.72 kB
JavaScript
/*
* Copyright 2015 Domabo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Module dependencies.
*/
var Promise = require('bluebird');
var send = require('./limesend.js');
/**
* Expose `serve()`.
*/
module.exports = serve;
/**
* Serve static files from `root`.
*
* @param {String} root
* @param {Object} [opts]
* @return {AppFunc}
* @api public
*/
function serve(root, opts) {
opts = opts || {};
// options
opts.root = root;
opts.index = opts.index || 'index.html';
return function owinStatic(next){
var owin = this;
// response is already handled
if (owin.response.statusCode != null) return;
return send(owin, owin.request.path, opts).then(function filesendContinuation(){
if (owin.response.statusCode == null)
{
owin = null;
return next()
}
owin = null;
});
}
}