dynamically remapping the root of static file service in a CherryPy app - cherrypy

I have an app that has two distinct pages in it - they do not share
auxilliary files and folders, where auxilliary files and folders are
css, js or images.
One app is served by default as the "index" of the domain
(e.g. `http://domain.name/') and the auxilliary files and folders are
in root of the source
tree.
The other app is served when the incoming url has superior appended
to it (e.g. http://domain.name/superior/). And in the superior
subdirectory of the
root
are where its auxilliary files and folders are.
As you can
see
I am trying to handle the superior path and dynamically change the
root for static files using _cp_config as discussed in the
docs:
#cherrypy.expose
def superior(self, s="supreme", cmpg=None, banner=None):
_cp_config = { 'tools.staticdir.root' : full_path('superior') }
return self.render(Superior(s))
however, debugging the app shows that it is still looking for all the
static files in the root of the source tree instead of the superior
subdirectory.
What do I need to do to configure CherryPy so that static resources
are searched for in this subdirectory of the root instead of the root?

I think that your method needs to be like this:
#cherrypy.expose
#cherrypy.config(**{'tools.staticdir.root' : full_path('superior')})
def superior(self, s="supreme", cmpg=None, banner=None):
return self.render(Superior(s))

Related

How to change the default path assets are served in SvelteKit?

I created a sample app using SvelteKit to perform SSR. I noticed the svelte assets are always downloaded following this path _app/immutable/.. (examples):
http://localhost:3000/_app/immutable/start-9080d3a7.js
http://localhost:3000/_app/immutable/chunks/index-cad423a5.js
http://localhost:3000/_app/immutable/layout.svelte-eb403b25.js
http://localhost:3000/_app/immutable/pages/up-homeui/index.svelte-d6a3b39b.js
http://localhost:3000/_app/immutable/error.svelte-3f23e1a2.js
How can I serve the assets at the root level, like:
http://localhost:3000/start-9080d3a7.js
http://localhost:3000/index-cad423a5.js
http://localhost:3000/layout.svelte-eb403b25.js
http://localhost:3000/index.svelte-d6a3b39b.js
http://localhost:3000/error.svelte-3f23e1a2.js
At the end, I would like to serve all the files at the same level.
I already played with the svelte.config and the vite.config but I couldn't find a way to change this default behavior.

Securing files in Google Cloud app engine (NodeJS)

I have created a small web application with NodeJS Express. Basically a webserver that has a 'webserver.properties' file. With a very basic app.yaml file.
After deploying it to Google Cloud by use of 'gcloud app deploy' I get the everything up and running.
However...when I open the following URL in the browser: https://webserverurl.com/webserver.properties , the webserver.properties file can be approached and is in turn downloaded immediately.
How can I prevent this from happening and make sure that such properties files are inaccessible from outside?
The problem is that when you use this line:
app.use('/', express.static(__dirname + '/'));
you are giving access to your root directory. See this for a definition of __dirname. If you want to give access to a specific folder you can do this:
Lets say your root directory is src and you fave a dir with static files called src/myfiles. In order to give acces to files in myfiles you can use this line:
app.use('/mypathname', express.static('myfiles'));
where:
'/mypathname' is the part pertaining your URL. In your case it would be https://webserverurl.com/mypathname/any-file-name.jpg
express.static('myfiles') is the name of your local dir.
See this guide.
Hope this helps

Can the Virtual File System In Service Stack Be configured not not treat files with multiiple dots as directories?

I'm attempting to serve an angular spa from embedded resources using the ServiceStack Virtual file system.
This appears to be mostly working, however many of my generated files include two dots in the file name like:
inline.bundle.js
I expected that would be served from:
host:port/inline.bundle.js
but it is actually served from
host: port/inline/bundle.js
The virtual filesystem appears to namespace based on the dot. Is there a way to configure it other wise so multiple dots in the last file are not interpretted as directories?
I'm using the angualr-cli to build the app, and it does not expose a way to modify the webpack config generating the bundles, otherwise I would just modify the file names.
The issue is that Embedded Resources don't include paths when the file is embedded so a file in a folder like /inline/bundle.js is embedded with the same resource name that /inline.bundle.js is, i.e: AssemblyNamespace.inline.bundle.js and it's up to ServiceStack's ResourceVirtualDirectory to use common heuristics to predict what the folder is.
You can force the ResourceVirtualPathProvider to treat a file by specifying it in:
SetConfig(new HostConfig {
EmbeddedResourceTreatAsFiles = { "inline.bundle.js" }
});

How do you change the express static directories?

I am working on a development platform, I have code similar to the following:
app.use('/public', express.static( config.directory.public ));
The issue is that there are many (100s) of projects each with its own directory structure. The project will be selected via the URL:
http://localhost/dev/accounts
Where accounts is a project with its own directory tree and static public directory.
I do not want to run a separate copy of node for each project. Once a project has been selected via the URL then express needs to be reconfigured to serve files for that request.
However, that approach is probably not feasible because we may be working on many projects at the same time. So every request for static files would have to be processed according to the project URL. It seems to negate the benefit of static directories.
I think what I am after is a way to put variables into the directory path
http://localhost/dev/accounts
Would set a variable called prj = "accounts" and then somehow set express so that the root directory is "c:\projects\" + prj + "\public".
If I simply issue a new app.use(..) statement for every request I imagine bad things will happen.
Maybe I am better off just manually reading the file contents for each static request and sending the contents back.
Is there another way to approach this problem?
I'm not sure if I understood your question correctly, but express serves static files in file directories automatically for you. If you have a bunch of projects in some 'path/to/public' folder, you just need to do something like
app.use('/', express.static( __dirname + '/public' ));
That way, you just need to type some url like
http://localhost/project1
or
http://localhost/project2

getting the static directory with nodejs using express?

i have set the static web directory for use in my nodejs app:
app.use express.static(process.cwd(), 'www')
This brings up all the static files like css, images etc, when im in the root it works
http://localhost:8124/
however if i go to somewhere like /tags, it deosnt bring up the static files:
http://localhost:8124/tags/
i get 404 error on the console because its trying to access the www folder
with
/tags/www/ ....
im not sure how to solve this problem, thanks
It looks like you're referring to static assets, without leading /, this results in appending relative asset address to the current URL. Instead refer to your static assets with leading /
eg. /www/style.css rather than www/style.css

Resources