public
Created

Examples of server side "bridge" for node-ares-data package in Nette framework, clean PHP and in Express.js framework.

  • Download Gist
AresPresenter.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
<?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));
}
 
}
bridge.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
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);
bridge.php
PHP
1 2 3 4 5 6 7 8
<?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;

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.