本文整理匯總了TypeScript中express.Response.sendFile方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Response.sendFile方法的具體用法?TypeScript Response.sendFile怎麽用?TypeScript Response.sendFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類express.Response
的用法示例。
在下文中一共展示了Response.sendFile方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: renderFile
public static renderFile(req: Request, res: Response, next: NextFunction) {
if (!req.resultPipe) {
return next();
}
return res.sendFile(req.resultPipe, {maxAge: 31536000});
}
示例2: sendFile
export function sendFile(path: string, filename: string, response: Response) {
//Send a file as response
let options = {
dotfiles: "deny",
headers: {
"x-timestamp": Date.now(),
"x-sent": true
}
};
let extension = filename.split(".").pop();
switch(extension) {
case "json":
response.type("application/json");
break;
case "properties":
response.type("text/x-java-properties");
break;
case "js":
response.type("text/javascript");
break;
case "css":
response.type("text/css");
break;
}
response.sendFile(
path + "/" + filename,
options,
function(err: Error | any) {
if (err && response.statusCode !== HttpStatus.NOT_MODIFIED && err.code !== "ECONNABORT") {
if (response.statusCode === HttpStatus.NOT_FOUND && filename !== placeholder) {
sendFile(path, placeholder, response);
} else {
// Do not log:
// - Requests aborted
// - 404 on minified script
//TODO is this still necessary?
if(err.message !== "Request aborted"
&& filename.match(/l4w\-.*\.min\.js/) === null) {
console.log("utils.sendFile - " + err);
console.error("error msg:" + err.message);
console.error("error name:" + err.name);
}
if(err.status !== undefined) {
response.status(err.status).send("");
} else {
response.status(HttpStatus.NO_CONTENT).send("");
}
}
}
}
);
};
示例3:
child_process.exec("cd HEC-RAS-Geometry-file-parser && ./hec uploads/" + req.file.originalname , (error, stdout, stderr) =>
{
if (error !== null)
{
console.log(error);
res.statusMessage = error.message;
res.status(500).end();
}
else
{
res.sendFile(path.join(__dirname, '../HEC-RAS-Geometry-file-parser/finalno.txt'));
}
});
示例4:
fs.exists(file, (exists: boolean) => {
if (!exists) {
return res.sendStatus(404);
}
res.sendFile(file);
});
示例5:
IndexRouter.get("/", (request: Request, response: Response, next: NextFunction) => {
response.sendFile(path.join(__dirname, "../../client", "index.html"))
})
示例6: function
app.get("/", function(req: Request, res: Response){
res.sendFile("index.html", {"root": "pages/"});
});
示例7: function
app.get('*', function(req: Request, res: Response) {
res.sendFile(__dirname + '/public/index.html'); // load the single view file (angular will handle the page changes on the front-end)
});
示例8:
app.get(/^\/((?:css|img|public)\/.+)$/, (req: Request, res: Response) => {
res.sendFile(path.join(projectRoot + 'client/public/') + req.params[0]);
});
示例9: function
index: function (req: Request, res: Response) {
// console.log(path.resolve(path.join(config.root, "client/index.html")));
res.sendFile(path.resolve(path.join(config.root, "client/index.html")));
}
示例10: function
app.get('/admin/', function(req, res: Response) {
res.sendFile(__dirname + '/frontend/build/admin.html');
});