serving static file not from /static in webpy - file

Is there a way of serving static files (images) not from the /static folder in webpy? What I would like to do is show images that are scattered in various directories, and moving all of them to /static is really not an option. If it is not feasible in webpy, are there any other python web frameworks that would do this?
Thanks,
v923z

You can easily do it when deploying your web.app under different webserver. But if you want to set static path in web.py development server then you'll have to patch webpy's static middleware or write your own. Please check my answer to the same question here: Changing the static directory path in webpy

Related

Defining a static directory into app.yaml make app crash

I have a weird issue on GAE standard (running node), more precisely with my app.yaml below.
runtime: nodejs8
# Environment variables
env_variables:
GOOGLE_CLOUD_PROJECT: '...'
# Static directories and files
handlers:
- url: /static
static_dir: public
Without the handlers part, everything works like a charm: my app is deployed and works. Note that the size is 4.8 MB (version 1-0-43).
However, with the handlers part, my app doesn't work anymore: 4xx error and an app size of 324 KB (version 1-0-43).
The sole purpose of the handlers part is to define a directory to serve static assets (CSS, JS, images...).
Any clue? Thanks.
When you add your static_dir handler definition the entire content of your public subdirectory is no longer (by default) uploaded together with your app code (most likely explaining the app size difference). Instead it's uploaded to a different location to be served directly by the GAE infra, see How to serve static files in AppEngine Standard and nodejs
It sounds that your app may need some of those files as well. In such case the easiest solution would be to add the application_readable flag to the static definition, causing that directory to be uploaded both in the static content location and together with your app code, see GAE: file_get_contents() and static files.
To speedup your deployments could also try to separate the static content in 2: one portion not needed by your app code, deployed without application_readable (thus not also uploaded with your app code, deployed faster) and one with the flag. If it's not too much trouble.
Could you try changing static_dir from 'public' to 'static'. Because the url and static_dir are usually located at the same place. Please try it and let me know. Cheers!
# Static directories and files
handlers:
- url: /static
static_dir: static

Is there a way to serve static resources with Traefik?

I'd like to serve static ressources such as images, js bundles, html pages... with Traefik like I was able to do with nginx
# nginx config
server {
root /www/data;
location ~ \.js {
root /www/bundles;
}
}
Many thanks
Cheers
Traefik doesn't serve static files (it's a not a web server it's a reverse proxy/load balancer).
You must use a container, which contains a web server with your files.
To extend the answer related to how files can be served:
If you are already serving files with nginx and want to migrate to Traefik you can still have nginx serving static files behind Traefik. I do this myself in hobby projects running docker standalone on a VM.
The best way is probably still to use containers/buckets such as S3 or Swift for static files as it will offload the traffic to the application server and provide a single location for these files (makes things easy when clustering) .. but if you don't have a lot of traffic and use a very simple setup, the nginx way is more than fine.
The issue around static files was discussed here : https://github.com/containous/traefik/issues/4240

How can I keep all my static content under content?

I have images, PDFs, etc. that I would like to store in one location (/content/) instead of /static/ folder for organizational reasons. Obviously, Hugo should copy this to static when I serve the webpage.
How can I do this?
Hugo can't copy things in the content/ directory to static/ by itself - you would have to use a pre-processor or post-processor like Grunt or gulp.

Grails 3.0 static html in run-app

similar questions have been asked before, regarding grails 2(.3, .4). I find it strange that i could not find a way to do this, as it seems a standard use-case to me.
I simply want to serve html-pages, including their linked .css and .js (angular and jquery content) when i run grails run-app.
I want to check if my http-calls are handeled correctly on both sides - without needing to deploy a .war and configuring a database.
afaik grails run-app simply starts a jetty/tomcat - both of which can obviously serve .html pages. What do i have to do to make the grails development-tooling deploy my files?
I need to make http-requests,
so using a different Server would violate JS-SOP,
while deploying the .war would greatly slow down the development process
I've so far only found clunky jsonp, proxy, .war deployment solutions, or solutions for grails 2.x
I tried placing the files literally everywhere in the projects' structure (/src/main, /src/main/resources, /src/main/public, the assets folder and its subfolders, created web-app directories in every subdirectory, the Init, domain, conf directories - you name it)
Add the index.html to src/main/resources/public
Then add this to UrlMappings.groovy:
"/"(redirect:"/index.html")
For grails >= 3.0.12
Location of static resources
In order to resolve an issue around how POST requests are treated for
REST applications on non-existent resources, static resources located
in src/main/resources/public are now resolved under the /static/** URI
by default, instead of the base URI /**. If you wish to restore the
previous behaviour add the following configuration:
grails.resources.pattern = '/**'
https://github.com/grails/grails-core/releases/tag/v3.0.12
Contrary to the accepted answer, you don't need a redirect. I have made able to make this work with the following config:
UrlMappings.groovy
"/"(uri: "/index.html")
application.yml
grails:
resources:
pattern: '/**'
Finally, you just need to have your index.html file located under src/main/webapp

Mixing static and dynamic endpoints in app.yaml file

I'm trying to describe endpoints in my App Engine app and am having difficulty for directory structures that mix static and dynamic content. But my yaml rules are conflicting with one another. Before I change my directory structure, does anyone have a recommendation?
The goal is to create a directory that contains both documentation (static html files) and implementations.
/api
- /v1
- getitdone.py
- doc.html
- index.html
What I think I should be doing with my application yaml...
- url: /api/v1/getitdone
script: api/v1/getitdone.py
- url: /api/
static_files: api/index.html
upload: api/index.html
- url: /api
static_dir: api
But this causes the dynamic endpoints to fail. I'm assuming the static_dir reference is breaking it. How can I do this without describing every script and static file reference (I have many more than are listed here)?
The cause of this is that you're marking /api/ as a static directory, so your scripts are getting uploaded as static files, which makes them inaccessible to the App Engine runtime.
The easiest solution would be to put your dynamic code and your static resources in different parts of your app's directory heirarchy, and use app.yaml to map them into the desired URL structure.

Resources