DefinitelyTyped/types/send/send-tests.ts
Joel a0d5848d4b send: removes setting default_type on mime in test..
.. as this is not possible (anymore) on the current library
2017-06-12 10:48:01 +01:00

37 lines
944 B
TypeScript

/// <reference types="express" />
import * as express from 'express';
import * as send from 'send';
var app = express();
send.mime.define({
'application/x-my-type': ['x-mt', 'x-mtt']
});
app.get('/test.html', (req, res) => {
send(req, '/test.html', {
maxAge: 0,
root: __dirname + '/wwwroot'
}).pipe(res);
});
app.get('/test.html', (req, res) => {
send(req, '/test.html')
.maxage(0)
.root(__dirname + '/wwwroot')
.on('error', (err: any) => {
res.statusCode = err.status || 500;
res.end(err.message);
})
.on('directory', () => {
res.statusCode = 301;
res.setHeader('Location', req.url + '/');
res.end('Redirecting to ' + req.url + '/');
})
.on('headers', (res: any, path: string, stat: any) => {
res.setHeader('Content-Disposition', 'attachment');
})
.pipe(res);
});