From 0fa4e9e61385646ea6a4cba2aef357353d2ce77f Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Mon, 4 Jan 2016 10:57:38 +0100 Subject: [PATCH 1/3] Remove trailing spaces --- serve-static/serve-static.d.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/serve-static/serve-static.d.ts b/serve-static/serve-static.d.ts index ef59fa2bc..29e5276cf 100644 --- a/serve-static/serve-static.d.ts +++ b/serve-static/serve-static.d.ts @@ -15,22 +15,22 @@ declare module "serve-static" { import * as express from "express"; - + /** - * Create a new middleware function to serve files from within a given root directory. - * The file to serve will be determined by combining req.url with the provided root directory. + * Create a new middleware function to serve files from within a given root directory. + * The file to serve will be determined by combining req.url with the provided root directory. * When a file is not found, instead of sending a 404 response, this module will instead call next() to move on to the next middleware, allowing for stacking and fall-backs. */ function serveStatic(root: string, options?: { /** - * Set how "dotfiles" are treated when encountered. A dotfile is a file or directory that begins with a dot ("."). - * Note this check is done on the path itself without checking if the path actually exists on the disk. - * If root is specified, only the dotfiles above the root are checked (i.e. the root itself can be within a dotfile when when set to "deny"). - * The default value is 'ignore'. - * 'allow' No special treatment for dotfiles - * 'deny' Send a 403 for any request for a dotfile - * 'ignore' Pretend like the dotfile does not exist and call next() - */ + * Set how "dotfiles" are treated when encountered. A dotfile is a file or directory that begins with a dot ("."). + * Note this check is done on the path itself without checking if the path actually exists on the disk. + * If root is specified, only the dotfiles above the root are checked (i.e. the root itself can be within a dotfile when when set to "deny"). + * The default value is 'ignore'. + * 'allow' No special treatment for dotfiles + * 'deny' Send a 403 for any request for a dotfile + * 'ignore' Pretend like the dotfile does not exist and call next() + */ dotfiles?: string; /** From db0118ada5f13b984a4b7900af1b0fe4b8f7e175 Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Mon, 4 Jan 2016 10:58:14 +0100 Subject: [PATCH 2/3] Definitions for serve-index (https://github.com/expressjs/serve-index) --- serve-index/serve-index-tests.ts | 72 ++++++++++++++++++++++++++++++++ serve-index/serve-index.d.ts | 42 +++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 serve-index/serve-index-tests.ts create mode 100644 serve-index/serve-index.d.ts diff --git a/serve-index/serve-index-tests.ts b/serve-index/serve-index-tests.ts new file mode 100644 index 000000000..5c4910af9 --- /dev/null +++ b/serve-index/serve-index-tests.ts @@ -0,0 +1,72 @@ +/// +/// + +import * as express from 'express'; +import * as serveIndex from 'serve-index'; +import * as fs from 'fs'; + +const app = express(); + +// Serve URLs like /ftp/thing as public/ftp/thing +app.use('/ftp', serveIndex('public/ftp', {'icons': true})); +app.listen(8080); + + +// Taken from https://github.com/expressjs/serve-index/blob/v1.7.2/test/test.js + +import * as path from 'path'; +var fixtures = path.join(__dirname, '/fixtures'); +const createServer = serveIndex; + +var server = createServer('test/fixtures', {'hidden': false}); + +var server = createServer('test/fixtures', {'hidden': true}); + +var server = createServer(fixtures, {'filter': filter}); +function filter(name: string): boolean { + if (name.indexOf('foo') === -1) return true + return false +} + +var server = createServer(fixtures, {'filter': filter, 'hidden': false}); + +var server = createServer(fixtures, {'icons': true}); + +var server = createServer(fixtures, {'template': __dirname + '/shared/template.html'}); + +var server = createServer(fixtures, {'template': function (locals, callback) { + callback(null, 'This is a template.'); +}}); + +var server = createServer(fixtures, {'template': function (locals, callback) { + callback(new Error('boom!')); +}}); + +var server = createServer(fixtures, {'template': function (locals, callback) { + callback(null, JSON.stringify(locals.directory)); +}}); + +var server = createServer(fixtures, {'template': function (locals, callback) { + callback(null, JSON.stringify(locals.displayIcons)); +}}); + +var server = createServer(fixtures, {'template': function (locals, callback) { + callback(null, JSON.stringify(locals.fileList.map(function (file) { + //file.stat = file.stat instanceof fs.Stats; + return file; + }))); +}}); + +var server = createServer(fixtures, {'template': function (locals, callback) { + callback(null, JSON.stringify(locals.path)); +}}); + +var server = createServer(fixtures, {'template': function (locals, callback) { + callback(null, JSON.stringify(locals.style)); +}}); + +var server = createServer(fixtures, {'template': function (locals, callback) { + callback(null, JSON.stringify(locals.viewName)); +}}); + +var server = createServer(fixtures, {'stylesheet': __dirname + '/shared/styles.css'}); diff --git a/serve-index/serve-index.d.ts b/serve-index/serve-index.d.ts new file mode 100644 index 000000000..34ba2fbbb --- /dev/null +++ b/serve-index/serve-index.d.ts @@ -0,0 +1,42 @@ +// Type definitions for serve-index v1.7.2 +// Project: https://github.com/expressjs/serve-index +// Definitions by: Tanguy Krotoff +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module 'serve-index' { + import * as express from 'express'; + import * as fs from 'fs'; + + namespace serveIndex { + interface File { + name: string; + stat: fs.Stats; + } + + interface Locals { + directory: string; + displayIcons: boolean; + fileList: Array; + name: string; + stat: fs.Stats; + path: string; + style: string; + viewName: string; + } + + type templateCallback = (error: Error, htmlString?: string) => void; + + interface Options { + filter?: (filename: string, index: number, files: Array, dir: string) => boolean; + hidden?: boolean; + icons?: boolean; + stylesheet?: string; + template?: string | ((locals: Locals, callback: templateCallback) => void); + view?: string; + } + } + + function serveIndex(path: string, options?: serveIndex.Options): express.Handler; + + export = serveIndex; +} From a6cd92e3b7f9478617fa84bbe4ba91158c4baea3 Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Tue, 5 Jan 2016 03:30:18 +0100 Subject: [PATCH 3/3] Fix "Cannot find module 'express'" error --- serve-index/serve-index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/serve-index/serve-index.d.ts b/serve-index/serve-index.d.ts index 34ba2fbbb..6b2ae6447 100644 --- a/serve-index/serve-index.d.ts +++ b/serve-index/serve-index.d.ts @@ -3,6 +3,8 @@ // Definitions by: Tanguy Krotoff // Definitions: https://github.com/borisyankov/DefinitelyTyped +/// + declare module 'serve-index' { import * as express from 'express'; import * as fs from 'fs';