forked from expressjs/express
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/old-master'
- Loading branch information
Showing
21 changed files
with
2,273 additions
and
852 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
language: node_js | ||
node_js: | ||
- "4.8" | ||
- "5.12" | ||
- "6.12" | ||
- "7.10" | ||
- "8.12" | ||
- "10.12" | ||
matrix: | ||
include: | ||
- node_js: "9" | ||
env: "NVM_NODEJS_ORG_MIRROR=https://nodejs.org/download/nightly" | ||
- node_js: "10" | ||
env: "NVM_NODEJS_ORG_MIRROR=https://nodejs.org/download/nightly" | ||
allow_failures: | ||
# Allow the nightly installs to fail | ||
- env: "NVM_NODEJS_ORG_MIRROR=https://nodejs.org/download/nightly" | ||
sudo: false | ||
cache: | ||
directories: | ||
- node_modules | ||
before_install: | ||
# Skip updating shrinkwrap / lock | ||
- "npm config set shrinkwrap false" | ||
|
||
# Remove all non-test dependencies | ||
- "npm rm --save-dev connect-redis" | ||
|
||
# Update Node.js modules | ||
- "test ! -d node_modules || npm prune" | ||
- "test ! -d node_modules || npm rebuild" | ||
script: | ||
- "npm run test-ci" | ||
- "npm run lint" | ||
after_script: "npm install [email protected] && cat ./coverage/lcov.info | coveralls" |
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/*! | ||
* serve-static | ||
* Copyright(c) 2010 Sencha Inc. | ||
* Copyright(c) 2011 TJ Holowaychuk | ||
* Copyright(c) 2014-2016 Douglas Christopher Wilson | ||
* MIT Licensed | ||
*/ | ||
|
||
'use strict' | ||
|
||
/** | ||
* Module dependencies. | ||
* @private | ||
*/ | ||
|
||
var parseUrl = require('parseurl') | ||
var resolve = require('path').resolve | ||
var fs = require('fs') | ||
|
||
/** | ||
* Module exports. | ||
* @public | ||
*/ | ||
|
||
module.exports = serveStatic | ||
|
||
/** | ||
* @param {string} root | ||
* @param {object} [options] | ||
* @return {function} | ||
* @public | ||
*/ | ||
|
||
function serveStatic (root, urlRoot, opts) { | ||
if (!root) { | ||
throw new TypeError('root path required') | ||
} | ||
|
||
if (typeof root !== 'string') { | ||
throw new TypeError('root path must be a string') | ||
} | ||
|
||
if(!opts) opts = {} | ||
|
||
// fall-though | ||
var fallthrough = opts.fallthrough !== false | ||
|
||
// headers listener | ||
var setHeaders = opts.setHeaders | ||
|
||
if (setHeaders && typeof setHeaders !== 'function') { | ||
throw new TypeError('option setHeaders must be function') | ||
} | ||
|
||
// setup options for send | ||
root = resolve(root) | ||
|
||
return function serveStatic (req, res, next) { | ||
if (req.method !== 'GET' && req.method !== 'HEAD') { | ||
if (fallthrough) { | ||
return next() | ||
} | ||
|
||
// method not allowed | ||
res.statusCode = 405 | ||
res.setHeader('Allow', 'GET, HEAD') | ||
res.setHeader('Content-Length', '0') | ||
res.end() | ||
return | ||
} | ||
|
||
var originalUrl = parseUrl.original(req) | ||
var path = parseUrl(req).pathname | ||
|
||
// make sure redirect occurs at mount | ||
if (path === '/' && originalUrl.pathname.substr(-1) !== '/') { | ||
path = '' | ||
} | ||
|
||
var filePath = root + "/" + path | ||
|
||
fs.access(filePath, fs.constants.R_OK, err=>{ | ||
if(err){ | ||
next() | ||
return | ||
} | ||
|
||
var urlPath = urlRoot + "/" + path | ||
res.sendFile(urlPath); | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.