在節點JS中,我如何創建一個端點通過? 我使用快遞和http 整個應用程序將只是一系列通過端點。 這裏是我的代碼在Node JS中,我如何創建端點傳遞?我使用快遞和http
// the real endpoint is somewhere else.
// for example http://m-engine.herokuapp.com/api/getstudents2
var http = require('http');
var options = {
host: 'http://m-engine.herokuapp.com',
path: '/api/getstudents2',
method: 'GET'
};
app.get('/api/getstudents', function(req, res){
// now past the request through
http.request(options, function(response2) {
response2.on('data', function (data) {
res.json(data);
});
}).end();
});
因此,無論何時任何api請求通過api endpoint/api/*到達域x,您都希望將它重定向到帶有endpoint/api/*的http://m-engine.herokuapp.com,這是您要實現的目標? –
難道你只是做'response2.pipe(res)',因爲你只是想讓它通過'可讀'和'可寫'流? – shriek
@HirenS。沒有沒有重定向,通過 – PrimeLens