Skip to content
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

Proxy subfolders #189

Closed
drj-io opened this issue Mar 27, 2017 · 6 comments
Closed

Proxy subfolders #189

drj-io opened this issue Mar 27, 2017 · 6 comments

Comments

@drj-io
Copy link

drj-io commented Mar 27, 2017

We have a main domain http://domain.com/ which is serving up our main document.

We have added a proxy route (AWS ALB) to serve Raneto from https://domain.com/docs/

We have changed "base_url" to "/docs", but nothing is served from there.

Logs show the following:

0|server   | GET /docs/ 404 4.870 ms - 2180
0|server   | GET /docs/lib/bootstrap/dist/css/bootstrap.min.css 304 2.712 ms - -
0|server   | GET /docs/lib/highlightjs/styles/solarized_light.css 304 1.680 ms - -
0|server   | GET /docs/styles/raneto.css 304 4.797 ms - -
0|server   | GET /docs/styles/ghostdown.css 304 5.429 ms - -
0|server   | GET /docs/lib/jquery/dist/jquery.min.js 304 8.428 ms - -
0|server   | GET /docs/lib/bootstrap/dist/js/bootstrap.min.js 304 9.149 ms - -
0|server   | GET /docs/lib/highlightjs/highlight.pack.min.js 304 9.042 ms - -
0|server   | GET /docs/lib/fitvids/fitvids.min.js 304 8.891 ms - -
0|server   | GET /docs/lib/masonry-layout/dist/masonry.pkgd.min.js 304 9.202 ms - -
0|server   | GET /docs/scripts/ghostdown.js 304 7.922 ms - -
0|server   | GET /docs/scripts/raneto.js 304 8.475 ms - -

We basically want the index of the knowledgebase to be served from "/docs/", not from "/". Is this possible without modifying the application code? The load balancer does not have the option to proxy relative paths, from my understanding.

The other alternative is to put another loadbalancer (nginx) on top of this to forward requests and alter the incoming path (from "/docs/" to "/"), but this is overkill in my opinion. We would possibly need to do a subdomain otherwise, which we're not excited about.

Interested in hearing your ideas. Thanks!

@drj-io
Copy link
Author

drj-io commented Mar 27, 2017

I have mostly fixed this by editing app/index.js and using the express-urlrewrite middleware: https://github.com/kapouer/express-urlrewrite

And also moved public theme assets to themes/default/public/docs

Here's what I did:

  • npm install express-urlrewrite
  • add property to the config: rewrite_prefix: '/docs',
  • bring in the dependency to app/index.js -> var rewrite = require("express-urlrewrite");
  • use the middleware: app.use(rewrite(config.rewrite_prefix + '/*','/$1'));

This takes care of most of the static routes that our users will need. It appears, however, that the login features are now broken, and who knows about the editing capability.

If this is something you guys would like to iterate with me on, I can submit a PR. Or if there's a better way, let me know... Thanks.

EDIT:

Fixed the style issues on the login page by adding config to the route:

'use strict';

function route_login_page (config) {
  return function (req, res, next) {

    return res.render('login', {
      config      : config,
      layout      : null,
      lang        : config.lang,
      rtl_layout  : config.rtl_layout,
      googleoauth : config.googleoauth
    });

  };
}

// Exports
module.exports = route_login_page;

There are still issues with static assets. I had to move themes/default/public to themes/default/public/docs to make that work, but the URLs are hard coded in the client side JS, so I'd have to change that too.

@GrahamDumpleton
Copy link
Contributor

Issues relates to login page and editing when using base url hopefully addressed by PR #280.

@ryanlelek
Copy link
Owner

Closing due to Graham's PR.
Please reopen if the issue continues.

Thanks Graham!

@allout58
Copy link

allout58 commented Jan 3, 2020

I can't seem to get this to work.... If I set the base_url to /raneto, the index page loads, but everything else returns HTTP 500 (should be 404? Looking at the logs, it says this page doesn't exist). It looks to be trying to GET /raneto/ for the index page ✔️ , and tries for /raneto/styles/raneto.css for example which it fails to find ❌

@ryanlelek
Copy link
Owner

Yep, I tested it again just now from a fresh clone.
Confirming:

  • The index page renders
  • The index page has broken asset links (CSS/JS)
  • Linked documents/pages do not render any content, instead 404

@ryanlelek
Copy link
Owner

Please see this branch/PR to address your issue and confirm/deny the fix.
#312

@ryanlelek ryanlelek reopened this Jan 4, 2020
ryanlelek added a commit that referenced this issue Sep 17, 2020
Fix: #189 Respect base_url setting and serve content and assets
AnkushLambdatest pushed a commit to AnkushLambdatest/Raneto that referenced this issue Jun 29, 2022
Fix: ryanlelek#189 Respect base_url setting and serve content and assets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants