Created
September 23, 2013 09:00
-
-
Save davidkudera/6668126 to your computer and use it in GitHub Desktop.
Examples of server side "bridge" for node-ares-data package in Nette framework, clean PHP and in Express.js framework.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Nette\Application\Responses\TextResponse; | |
/** | |
* Ares presenter | |
* | |
* @author David Kudera | |
*/ | |
class AresPresenter extends BasePresenter | |
{ | |
const URL = 'http://wwwinfo.mfcr.cz/cgi-bin/ares/darv_std.cgi'; | |
public function actionLoad() | |
{ | |
$query = $this->getHttpRequest()->getUrl()->getQuery(); | |
$data = file_get_contents(self::URL. '?'. $query); | |
$this->getHttpResponse()->setHeader('Content-type', 'text/xml'); | |
$this->sendResponse(new TextResponse($data)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
// uses express.js framework: https://npmjs.org/package/express | |
var express = require('express'); | |
// uses browser-http package: https://npmjs.org/package/browser-http | |
var httpHelpers = require('browser-http/Helpers'); | |
var app = express(); | |
var url = 'http://wwwinfo.mfcr.cz/cgi-bin/ares/darv_std.cgi?'; | |
app.get('/', function(req, res) { | |
res.header('Content-type', 'text/xml'); | |
var query = httpHelpers.buildQuery(req.query); | |
http.get(url + query, function(r) { | |
var result = []; | |
r.on('data', function(data) { | |
result.push(data) | |
}); | |
r.on('end', function() { | |
res.send(result.join('')) | |
}); | |
}); | |
}); | |
app.listen(3000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('ARES_URL', 'http://wwwinfo.mfcr.cz/cgi-bin/ares/darv_std.cgi'); | |
$data = file_get_contents(ARES_URL. '?'. $_SERVER['QUERY_STRING']); | |
header('Content-type: text/xml'); | |
echo $data; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment