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

-bake does not work #5

Open
ad-si opened this issue Jun 10, 2018 · 3 comments
Open

-bake does not work #5

ad-si opened this issue Jun 10, 2018 · 3 comments

Comments

@ad-si
Copy link

ad-si commented Jun 10, 2018

$ sprinkles -bake
BakeProject "./baked" (ServerConfig {scBackendCache = [], scDriver = DefaultDriver, scLogger = Nothing, scSessions = SessionConfig {sessCookieName = "ssid", sessCookieSecure = True, sessExpiration = NeverExpire, sessDriver = NoSessionDriver}, scRootDir = ""})
Baking project into ./baked
GET /123087408972309872109873012984709218371209847123 404 Not Found
text/html;charset=utf8
GET / 200 OK
application/json
./baked: openBinaryFile: inappropriate type (Is a directory)

$ tree
.
├── baked
│   └── _errors
│       └── 404.html
├── data
├── project.yml
└── templates
    ├── 404.html
    └── page.html
@tdammers
Copy link
Owner

Care to share your project.yml and templates?

@ad-si
Copy link
Author

ad-si commented Jun 10, 2018

@tdammers
Copy link
Owner

This is a peculiar situation: the / route produces a JSON response, and the -bake command handles these by simply dumping the JSON output into the file that corresponds to the route.

The problem here, however, is that since we're processing the root URL, that file amounts to ./baked, which is a directory, so we can't write our JSON data into that.

This is actually a more general problem though; if, for example, you were to have, say, the following routes:

  1. { pattern: '/foo', data: { ... } }
  2. { pattern: '/foo/bar', data: { ... } }

Note that both routes default to producing JSON output, so the -bake command would have to create the following two files:

  1. ./baked/foo
  2. ./baked/foo/bar

But that would require ./baked/foo to be a directory in the second case, and a file in the first case.

It works for HTML responses, because these are handled differently: if we add templates to those routes so that they render HTML, we get the following files:

  1. ./baked/foo/index.html
  2. ./baked/foo/bar/index.html

Now ./baked/foo is a directory in both cases, and everything works.

We could do the same for JSON responses, probably, but then we'd have to add a suitable additional default document to the .htaccess configuration (and thus we would be hardcoding the Apache dependency even harder than we already do).

For now, I think the best workaround is to just not have JSON routes that collide with directories; an approach that works well for anything other than / is to append .json to the route (which has the additional advantage that idiotic browsers like certain versions of IE, that have broken MIME type detection in some edge cases, will handle them correctly).

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

2 participants