valadoc-org icon indicating copy to clipboard operation
valadoc-org copied to clipboard

Serverside

Open btkostner opened this issue 8 years ago • 16 comments

Stop this madness!

This makes the index.php page render any template file. Basically making valadoc work without the need for javascript (yay?). The added benifit being that we can link files with nice, normal urls like such: http://localhost:7777/glib-2.0/GLib.FileUtils.html. I kept the old hash logic for anyone who still uses those. I also kept the client side page loading, but that could be removed without complication if we choose to.

This changes the way deployment is! You will need your nginx (or whatever your pick is) to try to return a file if it already exists, and fallback to the index.php script if no file is found.

Random other fixes:

  • Absolute paths for all resources (might fix #39)
  • Server rendering and friendly paths (fixes #45 and #56)

Testing welcome ;)

btkostner avatar Jul 30 '16 21:07 btkostner

the PHP part of me says do it, the JavaScript part says 'Noooo'.

The rest of me wishes we could use Vala instead of PHP :smile: .

While the current system is not ideal, not a fan of hashbang URLs either, putting it all server side isn't necessarily the best fix. All we achieve there is extra work for the server.

ZanderBrown avatar Jul 30 '16 23:07 ZanderBrown

It's not really doing extra work though. It's just interpreting real paths instead of hashes. Javascript is still doing the page loading after it's initial load as well, so there is that small speed boost.

As far as the back end, It just needs to stop being a jumble of different tech. I'm not a fan of the build system creating markup templates. Sadly that seems to be the biggest hurdle in redoing the site.

btkostner avatar Jul 30 '16 23:07 btkostner

I agree, this doesn't technically generate any new server workload, just different work.

lewisgoddard avatar Aug 02 '16 15:08 lewisgoddard

From the other ticket #56

I'd agree on the comments about doing everything in two or more places, it's a more than a bit confusing.

having to get .htaccess+nginx config correct plus php redirecting etc... - the bulk looks like it's already done in Javascript, so it looks better to keep the rest as simple as possible..

Something like at the top of the PHP code - and remove all the readfile() - would improve the security and simplicity no-end.

if(!empty($_SERVER['PATH_INFO'])) {
        header('Location: /index.php#!api='.preg_replace('/\.html$/','', $_SERVER['PATH_INFO']));
        exit;
}
if(!empty($_GET['page'])) {
        header('Location: /index.php#!api='.preg_replace('/\.html$/','', $_GET['page']));
        exit;
}
``

roojs avatar Sep 06 '16 07:09 roojs

Sorry for the late reply. I agree with the header redirect for api pages. This should reduce the complexity of the PHP side quite a bit. I'll fix it soon.

Although, I would REALLY recommend removing this javascript rendering logic, and doing strictly PHP with clean URLs.

btkostner avatar Sep 16 '16 09:09 btkostner

Would it be better if the urls were http://localhost:7777/glib-2.0/GLib.FileUtils, i.e. /{pkg}/{class}

benwaffle avatar Sep 17 '16 18:09 benwaffle

That would require additional server-side logic, I think. It would certainly be possible though.

lewisgoddard avatar Sep 17 '16 18:09 lewisgoddard

Alright. As a community we need to decide on this. Ignoring the implementation question, please answer how you want URLs. Voting closes on September 25th (little over a week).

:laughing: for urls like /{pkg}/{class} :heart: for urls as they currently are like #!wiki=cairo/index

btkostner avatar Sep 17 '16 19:09 btkostner

I'm in the 😄 group but we would have to be careful of the various site that use ❤️ links

ZanderBrown avatar Sep 17 '16 20:09 ZanderBrown

We should still be able to redirect from the hashed links to the correct page, no?

lewisgoddard avatar Sep 17 '16 20:09 lewisgoddard

Yes, but it will need to be client side, as hashes are not sent to the server

btkostner avatar Sep 17 '16 20:09 btkostner

I understand that, but a javascript snippet to redirect shouldn't be difficult. It only needs to be on the homepage.

lewisgoddard avatar Sep 17 '16 21:09 lewisgoddard

assuming

http://www.valadate.org:8000/#!api=gtk+-3.0/Gtk.AboutDialog

becomes

http://www.valadate.org:8000/gtk+-3.0/Gtk.AboutDialog

then

window.addEventListener('load', function() {
    location = location.hash.substr(6);
});

should work fine.

although URLs like

http://www.valadate.org:8000/#!wiki=gtk+-3.0/index

require further thought as my suggestion would redirect to

http://www.valadate.org:8000/=gtk+-3.0/index

EDIT

window.addEventListener('load', function() {
    if (location.hash.substr(2, 3) == 'api') {
        location = location.hash.substr(6);
    } else {
        location = location.hash.substr(7);
    }
});

that should do it

ZanderBrown avatar Sep 18 '16 09:09 ZanderBrown

To redirect: /#!api=gtk+-3.0/index to /gtk+-3.0/index and /#!wiki=gtk+-3.0/index to /gtk+-3.0/index

window.addEventListener('load', function() {
  if (
    location.hash.substr(2, 3) == 'api' ||
    location.hash.substr(2, 4) == 'wiki'
  ) {
    redirect_to = location.hash.split('=')
    location = '/' + redirect_to[1]
  }
});

lewisgoddard avatar Sep 28 '16 23:09 lewisgoddard

@lewisgoddard or that could work.... 😄

ZanderBrown avatar Sep 28 '16 23:09 ZanderBrown

@ZanderBrown My thought was that way whatever that first string is you just have to check for it, makes it easier to add new possibilities in case we missed any.

lewisgoddard avatar Sep 29 '16 01:09 lewisgoddard