Closed ITwrx closed 2 years ago
I tested it works as expected , use .
is expecting your cwd
that run your nim file as static dir, if you run appname.nim in /var/www/appname/
I think that's all fine. both putEnv
in .nim
file and in .nims
file in your case appname.nims
I've add proc doc comment ## Relys on
StaticDirenvironment variable
, the chronos have some problem with nimdoc so I can't just generate an api document on GitHub page.
i hadn't tried putting static files loose in the root dir. For me, scorper will serve any static files in the project root dir regardless of what i have for StaticDir
in static.nims
. Also, it won't serve any static files if i put them in a /static
dir even if i put ./static
as StaticDir
in static.nims
. Serving static files from a subdirectory only works if i add putEnv("StaticDir","./static")
to my main app file, as detailed above. Having static files loose in project root dir is not desirable to me, and it doesn't seem like the documented config method works for serving anywhere except the project root dir.
In your case is appname.nims ,use . Depends on your cwd. rest of url static/ will match files under static dir , that’s how it works
ok, (i'm still not sure what you're trying to tell me) but when i change the StaticDir to ./static in static.nims it doesn't respect that change. It only serves in cwd of appname.nim (project root). How are you supposed to use a dedicated directory for static files, using the static.nims file in your example and/or besides how i did it above?
My point is not that your code doesn't work, but that i don't understand your docs.
Maybe you could just show how to use a dedicated static dir (not loose files in project root) in the example? I can just use the method i found, but i just posted this issue so you would know it caused/causes me problems. Maybe other users will have trouble too. Maybe it's just me.
Okay , I get it . I am starting worry about writing document myself...
I'm probably missing something fundamental since i haven't used nim in a few months, but i was not able to serve static files until importing
os
and addingputEnv("StaticDir","./static")
to the main block in main file. I tried different locations for static.nims and paths as the StaticDir in static.nims, but couldn't get that to help anything.The below is what worked for me.
My static files are in a
/var/www/appname/static
directory.The main app file is
/var/www/appname/appname.nim
What am i missing? or maybe the docs for static files can be improved?
Thanks