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


TypeScript ServerResponse.end方法代碼示例

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


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

示例1: Date

    let server: Server = http.createServer((req: IncomingMessage, res: ServerResponse) => {
        if (req.method !== "GET") {
            return;
        }

        let parsedUrl: Url = url.parse(req.url, true);
        if (parsedUrl.pathname.lastIndexOf("/api/parsetime", 0) === 0) {
            let iso: string = parsedUrl.query.iso;
            let date: Date = new Date(iso);

            let responseDate: Object = {
                "hour": date.getHours(),
                "minute": date.getMinutes(),
                "second": date.getSeconds(),
            };
            res.end(JSON.stringify(responseDate));
            return;
        }

        if (parsedUrl.pathname.lastIndexOf("/api/unixtime", 0) === 0) {
            let iso: string = parsedUrl.query.iso;
            let date: Date = new Date(iso);

            let responseDate: Object = {
                "unixtime": date.getTime()
            };
            res.end(JSON.stringify(responseDate));
            return;
        }

        res.end();
    });
開發者ID:kyanro,項目名稱:nodeschool-learnyounode,代碼行數:32,代碼來源:main.ts

示例2: 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

示例3:

 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

示例4: createServer

const server = createServer((req: IncomingMessage, res: ServerResponse) => {

  const credentials = auth(req);

  if (!credentials || credentials.name !== 'john' || credentials.pass !== 'secret') {
    res.statusCode = 401;
    res.setHeader('WWW-Authenticate', 'Basic realm="example"');
    res.end('Access denied');
  } else {
    res.end('Access granted');
  }
});
開發者ID:types,項目名稱:npm-basic-auth,代碼行數:12,代碼來源:http.ts

示例5: validate

 private validate(req: ServerRequest, resp: ServerResponse) {
     let params = query.parse(url.parse(req.url).query)
     if (params['hub.mode'] === 'subscribe' && params['hub.verify_token'] === this.options.verifyToken) {
         resp.statusCode = 200
         resp.end(params['hub.challenge'])
         console.log('validation: ok')
     } else {
         resp.statusCode = 403
         resp.end()
         console.log('validation: fail')
     }
 }
開發者ID:nikinapi,項目名稱:Messenger-Bot,代碼行數:12,代碼來源:bot.ts

示例6: _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:bryanforbes,項目名稱:intern,代碼行數:7,代碼來源:Server.ts

示例7: catch

			request.on('end', () => {
				try {
					let rawMessages: any = JSON.parse(data);

					if (!Array.isArray(rawMessages)) {
						rawMessages = [rawMessages];
					}

					const messages: Message[] = rawMessages.map(function(
						messageString: string
					) {
						return JSON.parse(messageString);
					});

					this.executor.log('Received HTTP messages');

					Promise.all(
						messages.map(message => this._handleMessage(message))
					).then(
						() => {
							response.statusCode = 204;
							response.end();
						},
						() => {
							response.statusCode = 500;
							response.end();
						}
					);
				} catch (error) {
					response.statusCode = 500;
					response.end();
				}
			});
開發者ID:jason0x43,項目名稱:intern,代碼行數:33,代碼來源:Server.ts

示例8: return

  return (req: IncomingMessage, res: ServerResponse) => {
    // return 404 if path is /bogus-route to pass the test, lambda doesn't have paths
    if (req.url.includes('/bogus-route')) {
      res.statusCode = 404;
      return res.end();
    }

    let body = '';
    req.on('data', chunk => (body += chunk));
    req.on('end', () => {
      const urlObject = url.parse(req.url, true);
      const event = {
        httpMethod: req.method,
        body: body,
        path: req.url,
        queryStringParameters: urlObject.query,
        requestContext: {
          path: urlObject.pathname,
        },
        headers: req.headers,
      };
      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();
      };
      handler(event as any, {} as any, callback);
    });
  };
開發者ID:apollostack,項目名稱:apollo-server,代碼行數:35,代碼來源:lambdaApollo.test.ts

示例9: buf

 ctx.buffer = async function buf(body: Buffer) {
   if (Buffer.isBuffer(body)) {
     res.end(body);
   } else {
     throw new Error(`response.buffer expects a Buffer found ${typeof body}`);
   }
 };
開發者ID:mofax,項目名稱:leafless,代碼行數:7,代碼來源:body.ts

示例10:

 req.on('end', () => {
     //TODO: integrity check
     resp.statusCode = 200
     resp.end()
     this.handlePayload(JSON.parse(data))
     console.log('message receive: ok')
 })
開發者ID:nikinapi,項目名稱:Messenger-Bot,代碼行數:7,代碼來源:bot.ts


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