Skip to content

Commit

Permalink
Adds api_external config var.
Browse files Browse the repository at this point in the history
This allows us to make api calls internally while redirecting users to
the external api url for web links.
  • Loading branch information
oalders committed Feb 7, 2014
1 parent 33f5e71 commit 446a9ac
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 14 deletions.
12 changes: 8 additions & 4 deletions lib/MetaCPAN/Web/Controller/Root.pm
Expand Up @@ -85,16 +85,20 @@ sub end : ActionClass('RenderView') {
$c->stash->{req} = $c->req;
$c->stash->{api} = $c->config->{api};
$c->stash->{api_secure} = $c->config->{api_secure} || $c->config->{api};
$c->stash->{api_external}
= $c->config->{api_external} || $c->config->{api};
$c->res->header( Vary => 'Cookie' );

unless(
unless (
# Already have something set for fastly
$c->res->header('Surrogate-Control') ||

# We'll use Last-Modified for now
$c->res->header('Last-Modified')
) {
# Make sure fastly doesn't cache anything by accident
$c->res->header('Surrogate-Control' => 'no-store');
)
{
# Make sure fastly doesn't cache anything by accident
$c->res->header( 'Surrogate-Control' => 'no-store' );
}
}

Expand Down
7 changes: 4 additions & 3 deletions metacpan_web.conf
Expand Up @@ -3,9 +3,10 @@
name MetaCPAN::Web
default_view HTML

api http://api.metacpan.org
api_secure https://api.metacpan.org
consumer_key = metacpan.dev
api = http://api.metacpan.org
api_external = http://api.metacpan.org
api_secure = https://api.metacpan.org
consumer_key = metacpan.dev
consumer_secret = ClearAirTurbulence

<view HTML>
Expand Down
2 changes: 1 addition & 1 deletion root/browse.html
Expand Up @@ -15,7 +15,7 @@
<li class="nav-header">Tools</li>
<li><div><a href="/release/<% author %>/<% release %>/">Release Info</a></div></li>
<li><div><a href="/author/<% author %>/">Author</a></div></li>
<li><div><a href="<% api %>/source/<% base %>">Raw browser</a></div></li>
<li><div><a href="<% api_external %>/source/<% base %>">Raw browser</a></div></li>
<li class="nav-header">Info</li>
<li><% count = files.grep(->{this.directory == 'true'}).size; count %> folder<% count != 1 ? "s" : "" %></li>
<li><% count = files.grep(->{this.directory == 'false'}).size; count %> file<% count != 1 ? "s" : "" %></li>
Expand Down
4 changes: 2 additions & 2 deletions root/diff.html
Expand Up @@ -30,9 +30,9 @@
<li>
<div>
<%- IF type == 'source' %>
<a href="<% api %>/diff/file/<% diff.source.digest %>/<% diff.target.digest %>?content-type=text/plain">
<a href="<% api_external %>/diff/file/<% diff.source.digest %>/<% diff.target.digest %>?content-type=text/plain">
<%- ELSE %>
<a href="<% api %>/diff/release/<% diff.source %>/<% diff.target %>?content-type=text/plain">
<a href="<% api_external %>/diff/release/<% diff.source %>/<% diff.target %>?content-type=text/plain">
<%- END %>
Raw diff
</a>
Expand Down
4 changes: 2 additions & 2 deletions root/pod.html
Expand Up @@ -16,13 +16,13 @@
<li>
<div>
<a href="/source/<% module.author %>/<% module.release %>/<% module.path %>">Source</a>
(<a href="<% api %>/source/<% module.author %>/<% module.release %>/<% module.path %>">raw</a>)
(<a href="<% api_external %>/source/<% module.author %>/<% module.release %>/<% module.path %>">raw</a>)
</div>
</li>
<li>
<div>
<a href="/source/<% module.author %>/<% module.release %>/<% module.path.split("/").splice(0,-1).join("/") %>">Browse</a>
(<a href="<% api %>/source/<% module.author %>/<% module.release %>/">raw</a>)
(<a href="<% api_external %>/source/<% module.author %>/<% module.release %>/">raw</a>)
</div>
</li>
<% PROCESS inc/release-info.html %>
Expand Down
2 changes: 1 addition & 1 deletion root/release.html
Expand Up @@ -14,7 +14,7 @@
<%- IF changes %>
<li><a href="/<% changes.documentation ? "module" : "source" %>/<% release.author; '/'; release.name; '/'; changes.name %>">Changes</a></li>
<%- END %>
<li><span><a href="/source/<% release.author %>/<% release.name %>/">Browse</a> (<a href="<% api %>/source/<% release.author %>/<% release.name %>/">raw</a>)</span></li>
<li><span><a href="/source/<% release.author %>/<% release.name %>/">Browse</a> (<a href="<% api_external %>/source/<% release.author %>/<% release.name %>/">raw</a>)</span></li>
<% PROCESS inc/release-info.html %>
<li class="nav-header">Activity</li>
<% INCLUDE inc/activity.html query = 'distribution=' _ release.distribution %>
Expand Down
2 changes: 1 addition & 1 deletion root/source.html
Expand Up @@ -3,7 +3,7 @@
<strong><big>
<a href="/source/<% base = [module.author, module.release].join("/"); base %>"><% [module.author, module.release].join(" / ") %></a>
<% doc_view_url = [base,module.path].join("/") %>
<% raw_url = [api,'source',base,module.path].join("/") %>
<% raw_url = [api_external,'source',base,module.path].join("/") %>
<% FOREACH part IN module.path.split("/"); base = base _ "/" _ part -%>
/ <% UNLESS loop.last %><a href="/source/<% base %>"><% part %></a><% ELSE %><% part %><% END %>
<% END %>
Expand Down

0 comments on commit 446a9ac

Please sign in to comment.