當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Response.sendFile方法代碼示例

本文整理匯總了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});
  }
開發者ID:bpatrik,項目名稱:PiGallery2,代碼行數:7,代碼來源:RenderingMWs.ts

示例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("");
                    }
                }
            }
        }
    );
};
開發者ID:giovannipessiva,項目名稱:l4w,代碼行數:53,代碼來源:utils.ts

示例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'));
     }  
 });
開發者ID:filiptubic,項目名稱:HEC-RAS-Visualizer,代碼行數:13,代碼來源:geometry.ts

示例4:

 fs.exists(file, (exists: boolean) => {
   if (!exists) {
     return res.sendStatus(404);
   }
   res.sendFile(file);
 });
開發者ID:bpatrik,項目名稱:PiGallery2,代碼行數:6,代碼來源:PublicRouter.ts

示例5:

IndexRouter.get("/", (request: Request, response: Response, next: NextFunction) => {
  response.sendFile(path.join(__dirname, "../../client", "index.html"))
})
開發者ID:pabloalonsolopez,項目名稱:footbagent,代碼行數:3,代碼來源:index.ts

示例6: function

 app.get("/", function(req: Request, res: Response){
   res.sendFile("index.html", {"root": "pages/"});
 });
開發者ID:kongbb,項目名稱:MyFinance,代碼行數:3,代碼來源:index.route.ts

示例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)
    });
開發者ID:johnorland,項目名稱:try-node,代碼行數:3,代碼來源:app.ts

示例8:

 app.get(/^\/((?:css|img|public)\/.+)$/, (req: Request, res: Response) => {
     res.sendFile(path.join(projectRoot + 'client/public/') + req.params[0]);
 });
開發者ID:zhfuzzy,項目名稱:FullstackTypescript,代碼行數:3,代碼來源:app.ts

示例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")));
 }
開發者ID:lmaran,項目名稱:logspace,代碼行數:4,代碼來源:admin.controller.ts

示例10: function

app.get('/admin/', function(req, res: Response) {
  res.sendFile(__dirname + '/frontend/build/admin.html');
});
開發者ID:tebbon,項目名稱:nappikauppa2,代碼行數:3,代碼來源:app.ts


注:本文中的express.Response.sendFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。