当前位置: 首页>>代码示例>>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;未经允许,请勿转载。