Skip to content

baseURL option support. #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/controllers/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ Controller.prototype.renderHTML = function(status, file, locals) {
body = this.readFile(viewDir + file);

locals = locals || {};
locals.basePath = this.server._basePath;

var globals = {
scheme: this.request.secure ? 'https' : 'http',
host: this.getHost(),
basePath: this.server._basePath,
title: locals.title || '',
signup: this.server._allow.signup,
body: ejs.render(body.toString(), locals)
Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/web_finger.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ WebFinger.prototype.getOrigin = function() {
var scheme = (this.request.secure || this.server._forceSSL) ? 'https' : 'http',
host = this.request.headers['x-forwarded-host'] || this.request.headers.host;

return scheme + '://' + host;
return scheme + '://' + host + this.server._basePath;
};

module.exports = WebFinger;
12 changes: 11 additions & 1 deletion lib/restore.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var Restore = function(options) {
this._fileCache = {};
this._allow = options.allow || {};
this._cacheViews = options.cacheViews !== false;
this._basePath = options.basePath || ''

var self = this;

Expand Down Expand Up @@ -91,10 +92,19 @@ Restore.prototype.handle = function(request, response) {
Restore.prototype.dispatch = function(request, response) {
var method = request.method.toUpperCase(),
uri = url.parse(request.url, true),
match = null;
match = null,
startBasePath = new RegExp('^\/?' + this._basePath + '\/?');

request.secure = this.isSecureRequest(request);

if (!uri.pathname.match(startBasePath)) {
response.writeHead(302, {'Location': this._basePath})
return response.end()
}

// remove basePath before real path
uri.pathname = uri.pathname.replace(startBasePath, '/')

if (/(^|\/)\.\.(\/|$)/.test(uri.pathname)) {
response.writeHead(400, {'Access-Control-Allow-Origin': request.headers.origin || '*'});
return response.end();
Expand Down
2 changes: 1 addition & 1 deletion lib/views/auth.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h2>Authorize</h2>
<p class="error"><%= error %></p>
<% } %>

<form method="POST" action="/oauth">
<form method="POST" action="<%= basePath %>/oauth">
<input type="hidden" name="client_id" value="<%= client_id %>">
<input type="hidden" name="redirect_uri" value="<%= redirect_uri %>">
<input type="hidden" name="response_type" value="<%= response_type %>">
Expand Down
2 changes: 1 addition & 1 deletion lib/views/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p><img src="/assets/remotestorage.svg"></p>
<p><img src="<%= basePath %>/assets/remotestorage.svg"></p>

<p>This is <em>reStore</em>, an open-source <a
href="http://remotestorage.io/">remoteStorage</a> server. If you would like
Expand Down
6 changes: 3 additions & 3 deletions lib/views/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="<%= scheme %>://fonts.googleapis.com/css?family=Ubuntu+Mono|Open+Sans:400italic,400,700" rel="stylesheet" type="text/css">
<title><%= title %></title>
<link rel="stylesheet" type="text/css" href="/assets/style.css">
<link rel="stylesheet" type="text/css" href="<%= basePath %>/assets/style.css">
</head>
<body>

Expand All @@ -14,8 +14,8 @@
<h1><span>Remote Storage</span> <a href="/"><%= host %></a></h1>

<ul class="nav">
<li><a href="/">Home</a></li>
<% if (signup) { %><li><a href="/signup">Sign up</a></li><% } %>
<li><a href="<%= basePath %>/">Home</a></li>
<% if (signup) { %><li><a href="<%= basePath %>/signup">Sign up</a></li><% } %>
</ul>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion lib/views/signup.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h2>Sign up</h2>

<form method="post" action="/signup">
<form method="post" action="<%= basePath %>/signup">
<% if (error) { %>
<p class="error"><%= error.message %></p>
<% } %>
Expand Down