[英]Integration of `connect` on Node.Js failed
Node.Js上的connect
集成失敗,節點js
出現問題。 該腳本無法將其連接到api
。 在瀏覽器上顯示
不能獲取 /
這是教程, 請點擊這里
var express = require('express') var jwt = require('jsonwebtoken'); var app = express(); app.get('/PageAfterClickOnSubmitWithZainCash', function (req, res) { jwt.sign({ amount: 1000,//Product Ammout serviceType: 'AAA books website', msisdn: 9647911111111, orderId: 12345,//optional redirectUrl: "http://www.yourwebiste.com/zain_order.php",//optional }, 'secretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecret', { expiresIn: '4h' }, function (err, token) { request.post({ url: 'https://api.zaincash.iq/transaction/init', form: { token: token, merchantId: "572487bca0a4d6f2688c1ee3", lang: "ar"//optional } }, function (err, httpResponse, body) { var body = JSON.parse(body); // response of body { id : "asdae123asd123asd" } if (body.id) return res.redirect('https://api.zaincash.iq/transaction/pay?id=' + body.id); return res.redirect('/payment?msg=cannot_generate_token'); }) }); }); var connect = require('connect'); var serveStatic = require('serve-static'); var app = connect(); app.listen(5000); console.log('working on port 5000');
更新這是如何使服務器使用Connect
var connect = require('connect');
var http = require('http');
var app = connect();
app.use('/test', function fooMiddleware(req, res) {
res.end('test work')
});
//test work for me check your api request
http.createServer(app).listen(3000);
https://github.com/senchalabs/connect
我在本地運行您的代碼,即使沒有通過app.get('/test'..)
測試頁面。 我對express很滿意,因此著名的將建議Express.js
您正在混合表達和連接這是node.js的兩個不同框架
連接 :高性能中間件框架。 它由TJ Holowaychuk於2010年12月撰寫。
Express :快速,不受限制的簡約Web框架。 它由TJ Holowaychuk於2010年12月撰寫。express vs connect
這是我的代碼。.激活您的服務器沒有請求。它對測試請求的工作也希望對您的API請求有效
var express
= require('express')
var jwt = require('jsonwebtoken');
var app = express();
app.get('/test',function(req,res){
res.send('test work properly check your blah API')
})
app.use('/PageAfterClickOnSubmitWithZainCash', function (req, res) {
jwt.sign({
amount: 1000,//Product Ammout
serviceType: 'AAA books website',
msisdn: 9647911111111,
orderId: 12345,//optional
redirectUrl: "http://www.yourwebiste.com/zain_order.php",//optional
}, 'secretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecret', {
expiresIn: '4h'
}, function (err, token) {
request.post({
url: 'https://api.zaincash.iq/transaction/init',
form: {
token: token,
merchantId: "572487bca0a4d6f2688c1ee3",
lang: "ar"//optional
}
}, function (err, httpResponse, body) {
var body = JSON.parse(body); // response of body { id : "asdae123asd123asd" }
if (body.id)
return res.redirect('https://api.zaincash.iq/transaction/pay?id=' + body.id);
return res.redirect('/payment?msg=cannot_generate_token');
})
});
});
app.listen(5000);
console.log('working on port 5000');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.