如何使Node.js和Glassfish服务器侦听同一端口?
我正在使用Glassfish服务器运行我的web应用程序,该服务器在端口8080上运行。对于同一个web应用程序,我尝试使用node.js集成StripeAPI。我的web应用程序的其余部分在localhost:8080上运行 那么,我如何通过node.js和glassfish监听相同的8080端口,以便我的web应用程序与Stripe node.js集成 我应该使用web套接字吗 HTML页面:如何使Node.js和Glassfish服务器侦听同一端口?,node.js,glassfish,port,stripe-payments,Node.js,Glassfish,Port,Stripe Payments,我正在使用Glassfish服务器运行我的web应用程序,该服务器在端口8080上运行。对于同一个web应用程序,我尝试使用node.js集成StripeAPI。我的web应用程序的其余部分在localhost:8080上运行 那么,我如何通过node.js和glassfish监听相同的8080端口,以便我的web应用程序与Stripe node.js集成 我应该使用web套接字吗 HTML页面: <body> <form id="fo
<body>
<form id="form" action="/acctCreated" method="POST">
<label>Card #: <input type="text" size="16" data-stripe="number" placeholder="Card number" /></label>
<label>Expiry month: <input type="text" size="2" data-stripe="exp-month" placeholder="MM" /></label>
<label>year: <input type="text" size="2" data-stripe="exp-year" placeholder="YY" /></label>
<label>CVC: <input type="text" size="4" data-stripe="cvc" placeholder="CVC" /></label>
<button type="submit">Pay</button>
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://js.stripe.com/v2/"></script>
<script type="text/javascript">
Stripe.setPublishableKey('pk_test_mHCVXXlu5il6pgbQCQzmKY2S');
var $form = $('#form');
$form.on('submit', function() {
// First submit the card information to Stripe to get back a token
Stripe.card.createToken($form, function(status, response) {
var token = response.id;
// Save the token into a hidden input field
$form.append($('<input type="hidden" name="stripeToken" />').val(token));
// Now submit the form to our server so it can make the charge against the token
$form.get(0).submit();
});
return false;
});
</script>
</body>
谢谢,你不能直接这么做。您需要一个负载平衡器/路由器在前面监听8080 在端口8081上运行Glassfish,在8082上运行Node.js,然后在前面使用负载平衡器(例如,stud、haproxy、apache httpd或varnish),并将localhost:8081和localhost:8082设置为相应URL路径的后端 下面是一个这样使用HAProxy的示例 您可以使用单个HAProxy服务器根据URL和负载平衡隔离请求。 您的配置将如下所示:
frontend http
acl app1 path_end -i /app1/123 #matches path ending with "/app/123"
acl app2 path_end -i /app2/123
acl app3 path_end -i /app3/123
use_backend srvs_app1 if app1
use_backend srvs_app2 if app2
use_backend srvs_app3 if app3
backend srvs_app1 #backend that lists your servers. Use a balancing algorithm as per your need.
balance roundrobin
server host1 REGION1_HOST_FOR_APP1:PORT
server host2 REGION2_HOST_FOR_APP1:PORT
backend srvs_app2
balance roundrobin
server host1 REGION1_HOST_FOR_APP2:PORT
server host2 REGION2_HOST_FOR_APP2:PORT
backend srvs_app3
balance roundrobin
server host1 REGION1_HOST_FOR_APP3:PORT
server host2 REGION2_HOST_FOR_APP3:PORT
详情请浏览[网页][1]
[1] :
资料来源:
在Windows上,您可以在Apache httpd中使用mod_代理:
ProxyPass /nodejspath http://localhost:8081/nodejspath
ProxyPass /glassfishpath http://localhost:8081/glassfishpath
更多信息:Stripe API片段是从用户浏览器调用的,还是从Glassfish中servlet内部的业务逻辑调用的?它是从浏览器调用的。WebSocket用于面向消息的低级通信。这可能会使这件事复杂化,而不会给你任何价值。如果您必须在其他客户机发出其他请求时更新live order feed,这将是一个合适的选择。我继续跑WIndows@Shilpa这对你有用吗?如果是的话,你能接受它作为正确答案吗?
ProxyPass /nodejspath http://localhost:8081/nodejspath
ProxyPass /glassfishpath http://localhost:8081/glassfishpath