0

我想用 OpalRb Sprockets 使我的简单 sinatra 应用程序在 webrick https 上工作。

但它不起作用。对于每个生成的蛋白石 js 文件返回 404 :

[22/Oct/2019:17:48:17 HDT]“GET /assets/application.self-1919f5f7df8787d30bea01e4777248655a1ffc0533dcb37dedd4f797c018e19c.js?body=1 HTTP/1.1”404 555

[22/Oct/2019:17:48:16 HDT]“GET /assets/async/countdown.self-1a8c3d3b24219f07fe1d619745a23543afbc1862ed427e52d884ba406a0173ac.js?body=1 HTTP/1.1”404 564 https://localhost:44443/ -> /async/countdown.self-1a8c3d3b24219f07fe1d619745a23543afbc1862ed427e52d884ba406a0173ac.js?body=1 [2019-10-22 17:48:16] DEBUG Rack::Handler::WEBrick 被调用。127.0.0.1 - - [22/Oct/2019:17:48:16 -0900] “GET /assets/async/task.self-51bf482f4ed7ef3fb4dcdc63597ba56150e816bbdd68d6bc09c5e5f30f779723.js?body=1 ...

我假设 sprockets 路径未安装到 sinatra 应用程序。我启动服务器:“bundle exec rackup”

require 'webrick/https'
require 'webrick'

require 'bundler'

Bundler.require

### OPAL SPROCKETS ###

opal = Opal::Sprockets::Server.new {|s|
  s.append_path 'app'
  s.main = 'application'
}

sprockets   = opal.sprockets
prefix      = '/assets'

# WEBRICK HTTPS

CERT_PATH = 'cert/'.freeze

root = File.expand_path File.dirname(__FILE__) + "/public"

puts root

webrick_options = {
  Host: '0.0.0.0',
  Port: 4443,
  Logger: WEBrick::Log.new($stderr, WEBrick::Log::DEBUG),
#  DocumentRoot:  root,
  SSLEnable: true,
  SSLVerifyClient: OpenSSL::SSL::VERIFY_NONE,
  SSLCertificate: OpenSSL::X509::Certificate.new(File.open(File.join(CERT_PATH, 'chip.crt')).read),
  SSLPrivateKey: OpenSSL::PKey::RSA.new(File.open(File.join(CERT_PATH, 'chip.key')).read),
  SSLCertName: [['EN', '0.0.0.0']]
}

### APPLICATION ###

get '/' do
  @str_js_include = Opal::Sprockets.javascript_include_tag('application', sprockets: sprockets, prefix: prefix, debug: true).to_s

  erb :main
end

get '/test' do
  erb :test
end

get '/login' do
  erb :login
end

map prefix do
  # Rack::Handler::WEBrick.run sprockets - tried to do like that, no success
  run sprockets
end


Rack::Handler::WEBrick.run Sinatra::Application, webrick_options```
4

1 回答 1

0

我刚刚尝试了https://github.com/opal/opal/tree/master/examples/sinatra中的示例,除了bundle update一切正常,也许问题与 SSL 配置有关?


这是我所做的日志

⤑ cd /tmp                                                                      ~
⤑ git clone https://github.com/opal/opal.git                              /p/tmp
Cloning into 'opal'...
remote: Enumerating objects: 198, done.
remote: Counting objects: 100% (198/198), done.
remote: Compressing objects: 100% (130/130), done.
remote: Total 53499 (delta 98), reused 128 (delta 68), pack-reused 53301
Receiving objects: 100% (53499/53499), 14.68 MiB | 3.96 MiB/s, done.
Resolving deltas: 100% (33321/33321), done.
⤑ cd opal                                                                 /p/tmp
opal:master ⤑ cd examples/sinatra/                                     /p/t/opal
opal/examples/sinatra:master ⤑ bundle                           /p/t/o/e/sinatra
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Bundler could not find compatible versions for gem "opal":
  In Gemfile:
    opal

    opal-sprockets was resolved to 0.4.2.0.11.0.3.1, which depends on
      opal (~> 0.11.0)

Could not find gem 'opal (~> 0.11.0)', which is required by gem
'opal-sprockets', in any of the relevant sources:
  source at `../..`
opal/examples/sinatra:master ⤑ bundle update                    /p/t/o/e/sinatra
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Using ast 2.4.0
Using bundler 1.17.3
Using concurrent-ruby 1.1.5 (was 1.0.5)
Using mustermann 1.0.3
Using nio4r 2.5.2
Using parser 2.6.5.0 (was 2.5.1.0)
Using opal 1.0.0 (was 0.11.99.dev) from source at `../..`
Using rack 2.0.7 (was 1.5.2)
Using sprockets 3.7.2
Using tilt 2.0.10 (was 1.4.1)
Using opal-sprockets 0.4.8.1.0.3.7 (was 0.4.2.0.11.0.3.1)
Using puma 4.2.1 (was 3.12.0)
Using rack-protection 2.0.7 (was 1.5.3)
Using sinatra 2.0.7 (was 1.4.5)
Bundle updated!
opal/examples/sinatra:master ⤑ rackup -s webrick                /p/t/o/e/sinatra
Failed to load WithCLexer, using pure Ruby lexer
[2019-10-23 00:10:29] INFO  WEBrick 1.4.2
[2019-10-23 00:10:29] INFO  ruby 2.6.2 (2019-03-13) [x86_64-darwin18]
[2019-10-23 00:10:29] INFO  WEBrick::HTTPServer#start: pid=83302 port=9292
::1 - - [23/Oct/2019:00:10:42 +0200] "GET / HTTP/1.1" 200 5838 2.4478
::1 - - [23/Oct/2019:00:10:43 +0200] "GET /assets/corelib/constants.self-80dbf2213eaec5647ef76fa6fc8593e4c771bcddc67625be34fd7bfbd89f9b30.js?body=1 HTTP/1.1" 200 2223 0.0008
::1 - - [23/Oct/2019:00:10:43 +0200] "GET /assets/corelib/enumerable.self-80ef36902d6203dfaf04b94495704663c728f02efe754543062c90a8d7174f45.js?body=1 HTTP/1.1" 200 144850 0.0046
::1 - - [23/Oct/2019:00:10:43 +0200] "GET /assets/corelib/basic_object.self-49c73c232695c14345fa5067d09b95ebaf91557150e74ff973167ae2c38da90e.js?body=1 HTTP/1.1" 200 19780 0.0010
::1 - - [23/Oct/2019:00:10:43 +0200] "GET /assets/corelib/helpers.self-e963491215f833f3b6a9402f27f52412e38c9aebee637b84a346fabce8dbb0c1.js?body=1 HTTP/1.1" 200 20455 0.0109
::1 - - [23/Oct/2019:00:10:43 +0200] "GET /assets/corelib/class.self-3835c2821b14957802d16b6001855860e6a2fb82f86539b203c6b29f7aed2609.js?body=1 HTTP/1.1" 200 8090 0.0117
::1 - - [23/Oct/2019:00:10:43 +0200] "GET /assets/corelib/comparable.self-c11a004e4182f82f3a73b09c97e0f88b03d801ca0346bcdd85428b03c960d703.js?body=1 HTTP/1.1" 200 10699 0.0073
::1 - - [23/Oct/2019:00:10:43 +0200] "GET /assets/corelib/number.self-25dba0d94768d60e90de07e3f672e54c86c972770ef527a2622ac09eddd3d0f1.js?body=1 HTTP/1.1" 200 108046 0.0120
::1 - - [23/Oct/2019:00:10:43 +0200] "GET /assets/corelib/array.self-b0244c8e10e0fa340485716d73ba2abec3ec0817caf16a36b53c5684c9fde1c3.js?body=1 HTTP/1.1" 200 214431 0.0192
::1 - - [23/Oct/2019:00:10:43 +0200] "GET /assets/corelib/proc.self-981da1647c44c8edfe2dedda30c53634cc80d52f232d68a00fdd3c4939ea9717.js?body=1 HTTP/1.1" 200 14842 0.0155
::1 - - [23/Oct/2019:00:10:43 +0200] "GET /assets/opal/regexp_anchors.self-20cc626dd1d84867098e753dfae9f862d1a35e949792905b75b75a9c415e9ed5.js?body=1 HTTP/1.1" 200 5274 0.0093
::1 - - [23/Oct/2019:00:10:43 +0200] "GET /assets/corelib/file.self-97fd8e801a529c559e033244f64d05d98f3f49af78e69cb3181324a106ff93ea.js?body=1 HTTP/1.1" 200 30916 0.0022
::1 - - [23/Oct/2019:00:10:43 +0200] "GET /assets/corelib/math.self-e9ce73f7b73e64c2b4c168232e143a9f33a77ae381d81e9417699d36dbdf8f83.js?body=1 HTTP/1.1" 200 40945 0.0188
::1 - - [23/Oct/2019:00:10:43 +0200] "GET /assets/corelib/struct.self-1eaf6b9d43591c01545a1084d5bf8db634de3779caa254b7a9dd4a5be61fe9a9.js?body=1 HTTP/1.1" 200 48461 0.0200
::1 - - [23/Oct/2019:00:10:43 +0200] "GET /assets/application.self-59cd53c9a64be69736dc080a70b1b83e71772b601fba3c86019b3b51678f83de.js?body=1 HTTP/1.1" 200 1301 0.0178
::1 - - [23/Oct/2019:00:10:43 +0200] "GET /assets/opal/mini.self-35be78682bbabdd64a27877be288a0c9f38ec7f8a23312b64abc9a298b5cb442.js?body=1 HTTP/1.1" 200 2456 0.0445
于 2019-10-22T22:16:47.637 回答