Skip to content
This repository
Browse code

Made hostname dynamic via $hostname variable which checks if ENV{APP_…

…DUCKPAN_SERVER_HOSTNAME} otherwise it defaults to 'duckduckgo.com'
  • Loading branch information...
commit 4a6d74fd2f4780365d47500242239d170ae01f48 1 parent c12e25b
moollaza authored

Showing 1 changed file with 9 additions and 7 deletions. Show diff stats Hide diff stats

  1. +9 7 lib/App/DuckPAN/Cmd/Server.pm
16 lib/App/DuckPAN/Cmd/Server.pm
@@ -28,29 +28,31 @@ sub run {
28 28
29 29 print "\n\nTrying to fetch current versions of the HTML from http://duckduckgo.com/\n\n";
30 30
  31 + my $hostname = defined $ENV{APP_DUCKPAN_SERVER_HOSTNAME} ? $ENV{APP_DUCKPAN_SERVER_HOSTNAME} : 'duckduckgo.com';
  32 +
31 33 my $fetch_page_root;
32   - if ($fetch_page_root = get('http://duckduckgo.com/')) {
  34 + if ($fetch_page_root = get('http://'.$hostname.'/')) {
33 35 io(file($self->app->cfg->cache_path,'page_root.html'))->print($self->change_html($fetch_page_root));
34 36 } else {
35 37 print "\nRoot fetching failed, will just use cached version..."
36 38 }
37 39
38 40 my $fetch_page_spice;
39   - if ($fetch_page_spice = get('http://duckduckgo.com/?q=duckduckhack-template-for-spice')) {
  41 + if ($fetch_page_spice = get('http://'.$hostname.'/?q=duckduckhack-template-for-spice')) {
40 42 io(file($self->app->cfg->cache_path,'page_spice.html'))->print($self->change_html($fetch_page_spice));
41 43 } else {
42 44 print "\nSpice-Template fetching failed, will just use cached version..."
43 45 }
44 46
45 47 my $fetch_page_css;
46   - if ($fetch_page_css = get('http://duckduckgo.com/style.css')) {
  48 + if ($fetch_page_css = get('http://'.$hostname.'/style.css')) {
47 49 io(file($self->app->cfg->cache_path,'page.css'))->print($self->change_css($fetch_page_css));
48 50 } else {
49 51 print "\nCSS fetching failed, will just use cached version..."
50 52 }
51 53
52 54 my $fetch_page_js;
53   - if ($fetch_page_js = get('http://duckduckgo.com/duckduck.js')) {
  55 + if ($fetch_page_js = get('http://'.$hostname.'/duckduck.js')) {
54 56 io(file($self->app->cfg->cache_path,'page.js'))->print($self->change_js($fetch_page_js));
55 57 } else {
56 58 print "\nJavaScript fetching failed, will just use cached version..."
@@ -114,7 +116,7 @@ sub change_html {
114 116 if ($_->attr('type') && $_->attr('type') eq 'text/css') {
115 117 $_->attr('href','/?duckduckhack_css=1');
116 118 } elsif (substr($_->attr('href'),0,1) eq '/') {
117   - $_->attr('href','http://duckduckgo.com'.$_->attr('href'));
  119 + $_->attr('href','http://'.$hostname.''.$_->attr('href'));
118 120 }
119 121 }
120 122
@@ -127,7 +129,7 @@ sub change_html {
127 129 if ($src =~ m/^\/d\d{3}\.js/) {
128 130 $_->attr('src','/?duckduckhack_js=1');
129 131 } elsif (substr($src,0,1) eq '/') {
130   - $_->attr('src','http://duckduckgo.com'.$_->attr('src'));
  132 + $_->attr('src','http://'.$hostname.''.$_->attr('src'));
131 133 }
132 134 }
133 135 }
@@ -138,7 +140,7 @@ sub change_html {
138 140
139 141 for (@img) {
140 142 if ($_->attr('src')) {
141   - $_->attr('src','http://duckduckgo.com'.$_->attr('src'));
  143 + $_->attr('src','http://'.$hostname.''.$_->attr('src'));
142 144 }
143 145 }
144 146

0 comments on commit 4a6d74f

Please sign in to comment.
Something went wrong with that request. Please try again.