如果不调用机架/葡萄 api 端点,OCRA 会丢失库的子模块 [英] OCRA missing submodules of libraries if rack/grape api endpoints aren't called
问题描述
我正在尝试使用 OCRA 将我的 REST 应用程序打包到可执行文件中.我的脚本中需要一些宝石:
I'm trying to pack my REST app into into an executable with OCRA. I have a few gems required in my script:
require 'rack'
require 'rack/server'
require 'grape'
require 'grape-entity'
require 'rubygems'
我跳过用这个启动服务器:
I skip starting the server with this:
if not defined?(Ocra)
Rack::Server.start options
end
当我尝试运行我的 server.exe 时:
When I try to run my server.exe:
Temp/../server.rb:221:in `default_middleware_by_environment':
cannot load such file -- rack/content_length (LoadError)
这意味着它不检测存在但未使用因此不包括在内的机架子模块.如果我添加一个 require 'rack/content_length' 它会继续
cannot load such file -- rack/chunkedEven` 等等.
Which means that it doesn't detect submodules of rack that exist, but aren't used and therefore not included. If I add a require 'rack/content_length' it continues with
cannot load such file -- rack/chunkedEven` and so on.
当我手动中断服务器时,我还不得不调用一些 api 端点以包含所有内容.
When I interrupted my server by hand before I also had to call a few api endpoints to have everything included.
我认为我的选择是:
告诉 OCRA 包含rack 和grave 的所有子模块,但编译该列表有点耗时,并且会增加文件大小
Tell OCRA to include all the submodules of rack and grape, but compiling that list is a bit time consuming and would increase the file size
我已经尝试过 ocra server.rb --gem-full=rack --gem-full=grape
,它可以启动我的服务器,但是在调用 API 'rack/mount/strexp' 时又不见了..
I already tried ocra server.rb --gem-full=rack --gem-full=grape
, which get my server started, but when calling the API 'rack/mount/strexp' is missing again..
在我的脚本中调用 API,但我不知道该怎么做.我无法向 Rack::Server.start options
添加块,它只会在我中断服务器时继续.
Calling the API within my script, but I couldn't figure out how to do that. I can't add a block to Rack::Server.start options
and it does only continue when I interrupt the server.
有什么想法可以实现任一选项,还是有其他解决方案?
Any ideas to implement either option, or is there another solution?
推荐答案
如果我们使用机架处理程序(webrick/Thin/else)运行机架应用程序,我们可以在另一个线程中关闭服务器,以便 ocra 可以完成打包(不知道如何用 Rack::Server
做同样的事情.
If we run the rack app with a rack handler (webrick / thin / else), we can shutdown the server in another thread so that ocra can finish packing (not sure how to do same thing with Rack::Server
).
app = Rack::Directory.new ENV['HOME'] # a sample app
handler = Rack::Handler.pick %w/ thin webrick /
handler.run app do |server|
# handler.run yields a server object,
# which we shutdown when ocra is packing
if ocra_is_packing # replace with proper condition
Thread.new { sleep 10; server.shutdown }
end
end
您可能需要做其他事情(访问服务器等)才能让 ocra 打包适当的依赖项.
You may have to do something else (access the server etc.) to have ocra pack appropriate dependencies.
这篇关于如果不调用机架/葡萄 api 端点,OCRA 会丢失库的子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!