magnars / stasis

Some Clojure functions for creating static websites.
348 stars 27 forks source link

Allow for suffix-less file paths to return html content #13

Closed bcg closed 9 years ago

bcg commented 9 years ago

@magnars assuming this is not something you would want given the explicit design, but thought I might as well confirm.

If it is something you'd be interested in I could clean this up (statically-servable-uri?, project.clj, etc) or could simply better explain what I'm trying to achieve.

I'm pretty new to Clojure, if that isn't already apparent, though, so buyer beware.

magnars commented 9 years ago

See the readme for the breaking change in 2.0, which explicitly disallowed this. It also contains the reason why.

Thoughts?

bcg commented 9 years ago

I'm actually hoping to get the same behavior as http://site/post-title/index.html (rendering of a page without the html suffix) by forcing the desired content-type in the static file server and serving http://site/post-title directly.

For example, using S3: http://brenden.io/test-post

magnars commented 9 years ago

I see!

In that case I would like an option to toggle between the two styles - I don't want the two mixed in one app.

bcg commented 9 years ago

Not sure what the cleanest implementation would look like. Do you have something in mind?

I was thinking it initially it could use the same interfaces but special case the last type below so that when serve-pages is called it forces the Content-Type header to text/html instead of doing a 302. If people are trying to serve static file for downloading it would break this functionality in test mode.

test.html => test.html test/ => test/index.html test => test

The second option is to support the planned semantics in the README, but somehow make certain declared suffixes removed. We could pass a flag or something in the options hash of serve-pages and export but I think it may require you either have .html (or whatever) or not in your site. You couldn't mix and match.

The other option I was considering is to modify the map you pass to serve-pages and export (the get-pages param) so that the flag can be per url, but I think that changes the current API too significantly.

magnars commented 9 years ago

One thing occurred to me:

Isn't this just a prod-server setting?

The stasis export makes the correct directory structure for you. The dev-server will redirect from "/test" to "/test/", but that's no big bother.

Am I missing something?

bcg commented 9 years ago

Yea this is only an issue while testing locally. Without setting http://site/test 's Content-Type to text/html ring/stasis will serve up what the browser thinks is a file to download.

magnars commented 9 years ago

Hmm, there must be something I'm missing here.

So, how come your browser downloads a file when accessing http://site/test via ring/stasis? It should redirect.

bcg commented 9 years ago

Yea I'm personally looking for functionality where /test is a valid path to static file, not a redirect and not an exception. My end goal is to have urls like http://site/blog-post-title that don't do a 301 or 302 and don't need a trailing slash to inform the http server to resolve to http://site/blog-post-title/index.html.

As I said before, this may not be functionality you would like to support, but if it is I'm here to try and get it into master ...

magnars commented 9 years ago

If you can live with trailing slashes in dev, Stasis should work well out of the box. You can set up your server to serve slash-less URLs like a folder.

If you need Stasis to support URLs without trailing slashes in dev as well, then I'm for it if it can be done as an option with very light impact on the existing code. Otherwise I don't see the issue as important enough to warrant muddling up the code.