[英]How to add Specific Route in Phantomjs Webserver?
I am using Webserver to listen request on a particular host. 我正在使用Web 服务器来侦听特定主机上的请求。 I write ipaddress:port to listen a request. 我写ipaddress:port来监听请求。 But I want to add specific route into it. 但我想在其中添加特定的路线。 for eg -127.0.0.1:8080/test How I do that please help me? 例如-127.0.0.1:8080 / test我该怎么做请帮帮我?
Just like you would do in node.js. 就像在node.js中一样。 When a request comes in, then you can read the url
property of that request (and parse it yourself) and only answer requests that you want: 收到请求时,您可以读取该请求的url
属性 (并自行解析),并且仅回答所需的请求:
var webserver = require('webserver');
var server = webserver.create();
var service = server.listen(8080, function(request, response) {
if (request.url.indexOf("/test") !== -1) {
response.statusCode = 200;
response.write('<html><body>Success!</body></html>');
response.close();
} else {
response.statusCode = 404;
response.write('<html><body>Nothing to see here</body></html>');
response.close();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.