forked from DefinitelyTyped/DefinitelyTyped
-
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 pull request DefinitelyTyped#7474 from tkrotoff/serve-index
Definitions for serve-index (https://github.com/expressjs/serve-index)
- Loading branch information
Showing
3 changed files
with
127 additions
and
11 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,72 @@ | ||
/// <reference path="serve-index.d.ts" /> | ||
/// <reference path="../express/express.d.ts" /> | ||
|
||
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'}); |
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,44 @@ | ||
// Type definitions for serve-index v1.7.2 | ||
// Project: https://github.com/expressjs/serve-index | ||
// Definitions by: Tanguy Krotoff <https://github.com/tkrotoff> | ||
// Definitions: https://github.com/borisyankov/DefinitelyTyped | ||
|
||
/// <reference path="../express/express.d.ts" /> | ||
|
||
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<File>; | ||
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<File>, 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; | ||
} |
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