从 Sinatra 应用程序访问存储在服务器上的文件
我有一个机架空间云服务器,我在其上托管 Sinatra 应用程序。我的应用程序中有一个公共目录,我在其中存储当前的样式、脚本等。我有其他文件,但我不想在每次部署时更新和传输。我正在使用 git 和 Vlad 进行部署,为了避免这种情况,我当前的流程是
- 进行本地更改和更新,
- 更新我的本地存储库
- 推送到 git
- run vlad:update
- ,然后手动 ssh 到我的服务器并 mv mp3 和我想要在项目中的其他内容到当前版本的公共文件夹
简而言之,我希望能够访问我的用户文件夹中提供的文件,或者理想情况下还可以选择访问具有权限的服务器文件上的其他用户,这样我就不需要总是将它们移动到当前用手释放。
谢谢
I have a rackspace cloud server that I am hosting a Sinatra app on. I have a public directory in my app where I store my current styles, scripts, etc. I have additional files though that i dont want to be updating and transferring in with every deployment. I am using git and Vlad to deploy so to avoid this my current process is
- make local changes and updates
- update my local repo
- push to git
- run vlad:update
- then manually ssh into my server and mv the mp3s and other stuff I want in the project to the current releases' public folder
In short, I would like to be able to access files served in my user folder, or ideally also the option to access another user on the servers files with permissions, so that I don't need to always move them to the current release by hand.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您想直接从 Sinatra 提供静态文件(即您没有设置 Apache 或 Nginx 来提供它们),您可能可以使用
Rack::Static
。仅当静态文件全部由其他位置的子目录提供时,这才有效。例如,如果您在/home/other_user/files/mp3s
中存储了一堆 mp3,并且您像http://example.com/mp3s/foo.mp3
一样访问它们 code> 那么你可以像这样使用中间件:如果你还有其他子目录如果您想从“/images”等处提供文件,只需将它们添加到
:urls
数组中即可::urls => ['/mp3s', '/images']
。如果您希望能够访问 URL 'base' 处的文件,例如
http://example.com/foo.mp3
,则使用Rack::Static
不起作用。在这种情况下,我们需要针对目录检查每个请求,如果存在匹配的文件,则提供服务,否则继续处理请求。 (Sinatra 本身在检查其public
目录时必须执行类似的操作)。实现此目的的最简单方法可能是使用 来自rack-contrib的
Rack::TryStatic
:如果您使用其中任何一个,您可能需要确保只在正确的环境中配置中间件,否则您将出现错误查找不存在的目录时的开发。
Assuming you want to serve the static files directly from Sinatra (i.e. you don't have Apache or Nginx set up to serve them) you might be able to use
Rack::Static
. This will only work if the static files are all served from subdirectories of the other location. For example, if you have a bunch of mp3s stored in/home/other_user/files/mp3s
and you access them likehttp://example.com/mp3s/foo.mp3
then you could use the middleware like this:If you have other subdirectories you want to serve files from, e.g. '/images', simply add them to the
:urls
array::urls => ['/mp3s', '/images']
.If you want to be able to access the files at the 'base' of the url, like
http://example.com/foo.mp3
, thenRack::Static
wont work. In this case we need to check each request against the directory, and if a matching file exists serve it otherwise continue on with the request. (Sinatra itself has to do something like this when checking itspublic
directory).The easiest way to achieve this is probably to use
Rack::TryStatic
from rack-contrib:If you use either of these, you'll likely need to make sure you only configure the middleware in the right environment, otherwise you'll get errors in development when non-existent directories are looked for.