From 5497e8410b1dc6a15364d1d8238202fc7813a24f Mon Sep 17 00:00:00 2001 From: Atle Haugan Date: Fri, 19 Feb 2016 14:27:56 +0100 Subject: [PATCH] First version --- .gitignore | 3 +++ app.js | 28 ++++++++++++++++++++++++++++ client.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 14 ++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 .gitignore create mode 100644 app.js create mode 100644 client.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8756d60 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/ +*.iml +node_modules/ diff --git a/app.js b/app.js new file mode 100644 index 0000000..be20009 --- /dev/null +++ b/app.js @@ -0,0 +1,28 @@ +var express = require('express'); +var http = require('http'); +var app = express(); + + +app.get('/', function (req, res) { + // var eventUrl = 'http://event.polarismedia.no/adressa/search/?dateFrom=2016-02-20&dateTo=2016-03-05&categories=8&page=1'; + var eventUrl = "www.statoil.no"; + var options = { + host: "www-proxy.statoil.no", + port: 80, + path: eventUrl, + headers: { + Host: eventUrl + } + }; + http.get(options, function (res) { + console.log('STATUS: ' + res.statusCode); + console.log('HEADERS: ' + JSON.stringify(res.headers)); + res.setEncoding('utf8'); + res.on('data', function (chunk) { + console.log('BODY: ' + chunk); + }); }); +}); + +app.listen(3000, function () { + console.log('Example app listening on port 3000!'); +}); diff --git a/client.js b/client.js new file mode 100644 index 0000000..0a1e565 --- /dev/null +++ b/client.js @@ -0,0 +1,46 @@ +/** + * Created by ATLEH on 19.02.2016. + */ +var express = require('express'); +var http = require('http'); +var app = express(); + +app.get('/', function (req, res) { + // var url = 'http://event.polarismedia.no/adressa/search/?dateFrom=2016-02-20&dateTo=2016-03-05&categories=8&page=1'; + var eventHost = 'event.polarismedia.no'; + var eventPath = '/adressa/events/11948'; + var optionsWithProxy = { + host: "www-proxy.statoil.no", + port: 80, + path: "www.statoil.no", + headers: { + Host: "www.statoil.no" + } + }; + var optionsWithoutProxy = { + host: eventHost, + port: 80, + path: eventPath + }; + + // Callback function is used to deal with response + var callback = function (response) { + // Continuously update stream with data + var body = ''; + response.on('data', function (data) { + body += data; + }); + + response.on('end', function () { + // Data received completely. + console.log(body); + }); + }; +// Make a request to the server + var req = http.request(optionsWithoutProxy, callback); + req.end(); +}); + +app.listen(3000, function () { + console.log('Example app listening on port 3000!'); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..f96f5f0 --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "whatsup", + "version": "1.0.0", + "description": "", + "main": "app.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "express": "^4.13.4" + } +}