-
-
Notifications
You must be signed in to change notification settings - Fork 382
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
Static File Server Endpoint #497
Comments
I've been thinking about how to implement this, but it seems quite difficult. Is there anyway that a special rule can be made, so all files in |
This is a current workaround I have, but it's not great: CROW_ROUTE(app, "/css/<string>")
([&app](const std::string& path) {
crow::response res;
res.body = getFileContents(getStaticPath("css", path));
res.add_header("Content-Type", "stylesheet");
return res;
});
CROW_ROUTE(app, "/js/<string>")
([](const std::string& path) {
crow::response res;
res.body = getFileContents(getStaticPath("js", path));
res.add_header("Content-Type", "text/javascript");
return res;
}); |
Changing
This is mostly up to the browser to do that, so a URL like For subdirectories like
I can see a few issues with this implementation. For starters, if you're going to use a response it would be best to use Another thing is using Lastly is that you can use Crow's |
Thanks for you response. I'll take a look at more of this tomorrow, but using the route with I didn't see blueprints when I went through the website docs. I'll take a look at that. Also, thanks for CROW_ROUTE(app, "/css/<string>")
([&app](const std::string& path) {
crow::response res;
res.response::set_static_file_info("/static/" + path;)
return res;
});
``` |
I'm guessing this is due to #469. It's been fixed in |
I'll close this for the time being. @AndruePeters let me know if you're facing issues still. |
Hey,
I've read documentation and looked at some issues, but I'm not sure how to fix this.
I don't want to have to prefix all links with "static".
I thought if I changed the endpoint prefix, then this would work.
#define CROW_STATIC_ENDPOINT "/<path>"
Shouldn't this redirect the endpoint
/path
to/static/path
?This still presents me with 404 errors, though. Is there a way to get the desired behavior? I'm testing multiple servers and really don't want to have to do
static/css/bootstrap.css
.The text was updated successfully, but these errors were encountered: