本文整理匯總了TypeScript中send.mime.define方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript mime.define方法的具體用法?TypeScript mime.define怎麽用?TypeScript mime.define使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類send.mime
的用法示例。
在下文中一共展示了mime.define方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
export default function() {
const serveStatic = require("serve-static");
/**
* Adding a custom mime-type for wasm whilst we wait for
* the `send` package to be updated.
*/
const send = require("send");
send.mime.define({ "application/wasm": ["wasm"] });
return serveStatic;
}
示例2: express
/// <reference path="send.d.ts" />
/// <reference path="../express/express.d.ts" />
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 + '/');