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


TypeScript http.ServerResponse類代碼示例

本文整理匯總了TypeScript中http.ServerResponse的典型用法代碼示例。如果您正苦於以下問題:TypeScript ServerResponse類的具體用法?TypeScript ServerResponse怎麽用?TypeScript ServerResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ServerResponse類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: createServer

var newServer = createServer((req: any, res: ServerResponse)=>{
    if (req.url =='/big.html')
    {
        
    }
    res.write("hi. its sample");
    res.end();
})
開發者ID:Ciget,項目名稱:node-empty-project,代碼行數:8,代碼來源:index.ts

示例2: nocache

  return function nocache (_req: IncomingMessage, res: ServerResponse, next: () => void) {
    res.setHeader('Surrogate-Control', 'no-store');
    res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
    res.setHeader('Pragma', 'no-cache');
    res.setHeader('Expires', '0');

    next();
  };
開發者ID:helmetjs,項目名稱:nocache,代碼行數:8,代碼來源:index.ts

示例3: write404

function write404(
  url: string | undefined,
  response: ServerResponse,
  logger: LoggerType
) {
  logger.error(`write404: Squirrel requested unexpected url '${url}'`);
  response.writeHead(404);
  response.end();
}
開發者ID:WhisperSystems,項目名稱:Signal-Desktop,代碼行數:9,代碼來源:macos.ts

示例4: _send404

	private _send404(response: ServerResponse) {
		response.writeHead(404, {
			'Content-Type': 'text/html;charset=utf-8'
		});
		response.end(
			'<!DOCTYPE html><title>404 Not Found</title><h1>404 Not Found</h1>' +
				`<!-- ${new Array(512).join('.')} -->`
		);
	}
開發者ID:jason0x43,項目名稱:intern,代碼行數:9,代碼來源:Server.ts

示例5: function

 return function (req: ServerRequest, resp: ServerResponse) {
     resp.setHeader('Content-Type', 'application/json')
     if (req.method === 'GET') {
         bot.validate(req, resp)
     } else if (req.method === 'POST') {
         bot.parseMessagingEvent(req, resp)
     } else {
         resp.statusCode = 400
         resp.end()
     }
 }
開發者ID:nikinapi,項目名稱:Messenger-Bot,代碼行數:11,代碼來源:bot.ts

示例6: makeSubpath

    form.parse(req, (err, fields:Fields, files:Files)=> {

        if (!files) {
            res.end(JSON.stringify({ok: false, error: "no_file_data"}));
        }

        var file = files["file"];
        var tmpPath = file.path;
        var subDir = makeSubpath(token);
        var newDir = '/thumbs/' + subDir;
        var newPath = newDir + "/" + jpgFile;

        fs.exists(newDir, (exists:boolean)=> {
            if (!exists) {
                // console.log("Folder " + newDir + " not exist");
                mkdirp(newDir, (err)=> {
                    if (err) {
                        res.end(JSON.stringify({ok: false, error: "cant_create_subdir"}));
                        console.error(err);
                    } else {
                        moveFile(tmpPath, newPath);
                    }
                });
            } else {
                moveFile(tmpPath, newPath);
            }
        });

        res.writeHead(200, {'content-type': 'text/plain'});
        res.end(JSON.stringify({ok: true, url: subDir + "/" + jpgFile}));
    });
開發者ID:terbooter,項目名稱:LVK-thumbs,代碼行數:31,代碼來源:app.ts

示例7:

 const end = (output: HandlerOutput<Value>) => {
   res.writeHead(200, { 'Content-Type': 'application/json' });
   const outputString = IS_NOW
     ? JSON.stringify(output)
     : JSON.stringify(output, null, 2);
   res.end(outputString);
 };
開發者ID:este,項目名稱:este,代碼行數:7,代碼來源:createHandler.ts

示例8:

 server.sendRequest(baseUrl + request.url, pathname[2], (res: Host.Response) => {
   response.writeHead(res.status, server.headers);
   if (res.success) {
     response.write(res.data);
     server.setCache(request.url, res.data);
   } else {
     response.write(res.data + '\n');
   }
   response.end();
 });
開發者ID:gitter-badger,項目名稱:LegendBuilder,代碼行數:10,代碼來源:static-server.ts

示例9:

 readstream.on("error", err => {
   if ((err.code = "ENOENT")) {
     // file not found
     res.statusCode = 404;
     res.end("Not Found");
   } else {
     console.error(err);
     res.statusCode = 500;
     res.end("Unknown Server Error");
   }
 });
開發者ID:mofax,項目名稱:leafless,代碼行數:11,代碼來源:util.ts

示例10:

 const callback = (error, result) => {
   if (error) throw error;
   res.statusCode = result.statusCode;
   for (let key in result.headers) {
     if (result.headers.hasOwnProperty(key)) {
       res.setHeader(key, result.headers[key]);
     }
   }
   res.write(result.body);
   res.end();
 };
開發者ID:apollostack,項目名稱:apollo-server,代碼行數:11,代碼來源:lambdaApollo.test.ts


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