mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
37 lines
982 B
TypeScript
37 lines
982 B
TypeScript
/// <reference types="express" />
|
|
|
|
import * as express from 'express';
|
|
import * as send from 'send';
|
|
|
|
var app = express();
|
|
|
|
send.mime.default_type = 'text/plain';
|
|
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);
|
|
}); |