opal-up 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +209 -0
- data/README.md +97 -29
- data/bin/up_ruby +4 -0
- data/bin/up_ruby_cluster +4 -0
- data/ext/up_ext/App.h +606 -0
- data/ext/up_ext/AsyncSocket.h +355 -0
- data/ext/up_ext/AsyncSocketData.h +87 -0
- data/ext/up_ext/BloomFilter.h +83 -0
- data/ext/up_ext/ChunkedEncoding.h +236 -0
- data/ext/up_ext/ClientApp.h +36 -0
- data/ext/up_ext/HttpContext.h +502 -0
- data/ext/up_ext/HttpContextData.h +56 -0
- data/ext/up_ext/HttpErrors.h +53 -0
- data/ext/up_ext/HttpParser.h +680 -0
- data/ext/up_ext/HttpResponse.h +578 -0
- data/ext/up_ext/HttpResponseData.h +95 -0
- data/ext/up_ext/HttpRouter.h +380 -0
- data/ext/up_ext/Loop.h +204 -0
- data/ext/up_ext/LoopData.h +112 -0
- data/ext/up_ext/MoveOnlyFunction.h +377 -0
- data/ext/up_ext/PerMessageDeflate.h +315 -0
- data/ext/up_ext/ProxyParser.h +163 -0
- data/ext/up_ext/QueryParser.h +120 -0
- data/ext/up_ext/TopicTree.h +363 -0
- data/ext/up_ext/Utilities.h +66 -0
- data/ext/up_ext/WebSocket.h +381 -0
- data/ext/up_ext/WebSocketContext.h +434 -0
- data/ext/up_ext/WebSocketContextData.h +109 -0
- data/ext/up_ext/WebSocketData.h +86 -0
- data/ext/up_ext/WebSocketExtensions.h +256 -0
- data/ext/up_ext/WebSocketHandshake.h +145 -0
- data/ext/up_ext/WebSocketProtocol.h +506 -0
- data/ext/up_ext/bsd.c +767 -0
- data/ext/up_ext/bsd.h +109 -0
- data/ext/up_ext/context.c +524 -0
- data/ext/up_ext/epoll_kqueue.c +458 -0
- data/ext/up_ext/epoll_kqueue.h +67 -0
- data/ext/up_ext/extconf.rb +5 -0
- data/ext/up_ext/internal.h +224 -0
- data/ext/up_ext/libusockets.h +350 -0
- data/ext/up_ext/libuwebsockets.cpp +1344 -0
- data/ext/up_ext/libuwebsockets.h +396 -0
- data/ext/up_ext/loop.c +386 -0
- data/ext/up_ext/loop_data.h +38 -0
- data/ext/up_ext/socket.c +231 -0
- data/ext/up_ext/up_ext.c +930 -0
- data/lib/up/bun/rack_env.rb +1 -13
- data/lib/up/bun/server.rb +93 -19
- data/lib/up/cli.rb +3 -0
- data/lib/up/client.rb +68 -0
- data/lib/up/ruby/cluster.rb +39 -0
- data/lib/up/ruby/cluster_cli.rb +10 -0
- data/lib/up/{node → ruby}/rack_cluster.rb +5 -4
- data/lib/up/{node → ruby}/rack_server.rb +4 -4
- data/lib/up/ruby/server_cli.rb +10 -0
- data/lib/up/u_web_socket/cluster.rb +18 -3
- data/lib/up/u_web_socket/server.rb +108 -15
- data/lib/up/version.rb +1 -1
- metadata +72 -30
- data/.gitignore +0 -5
- data/Gemfile +0 -2
- data/bin/up_node +0 -12
- data/bin/up_node_cluster +0 -12
- data/example_rack_app/Gemfile +0 -3
- data/example_rack_app/config.ru +0 -6
- data/example_rack_app/rack_app.rb +0 -5
- data/example_roda_app/Gemfile +0 -6
- data/example_roda_app/config.ru +0 -6
- data/example_roda_app/roda_app.rb +0 -37
- data/example_sinatra_app/Gemfile +0 -6
- data/example_sinatra_app/config.ru +0 -6
- data/example_sinatra_app/sinatra_app.rb +0 -7
- data/lib/up/node/cluster.rb +0 -39
- data/lib/up/node/cluster_cli.rb +0 -15
- data/lib/up/node/rack_env.rb +0 -106
- data/lib/up/node/server.rb +0 -84
- data/lib/up/node/server_cli.rb +0 -15
- data/lib/up/u_web_socket/rack_env.rb +0 -101
- data/opal-up.gemspec +0 -27
- data/up_logo.svg +0 -256
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-up
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logger
|
@@ -92,6 +92,20 @@ dependencies:
|
|
92
92
|
- - "~>"
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: 13.1.0
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rake-compiler
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.2.7
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 1.2.7
|
95
109
|
- !ruby/object:Gem::Dependency
|
96
110
|
name: rspec
|
97
111
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,59 +120,87 @@ dependencies:
|
|
106
120
|
- - "~>"
|
107
121
|
- !ruby/object:Gem::Version
|
108
122
|
version: 3.12.0
|
109
|
-
description: High performance Rack server for Opal Ruby
|
123
|
+
description: High performance Rack server for Opal and Ruby
|
110
124
|
email:
|
111
125
|
- jan@kursator.de
|
112
126
|
executables:
|
113
127
|
- up
|
114
128
|
- up_bun
|
115
129
|
- up_cluster
|
116
|
-
-
|
117
|
-
-
|
118
|
-
extensions:
|
130
|
+
- up_ruby
|
131
|
+
- up_ruby_cluster
|
132
|
+
extensions:
|
133
|
+
- ext/up_ext/extconf.rb
|
119
134
|
extra_rdoc_files: []
|
120
135
|
files:
|
121
|
-
- ".gitignore"
|
122
|
-
- Gemfile
|
123
136
|
- LICENSE
|
124
137
|
- README.md
|
125
138
|
- bin/up
|
126
139
|
- bin/up_bun
|
127
140
|
- bin/up_cluster
|
128
|
-
- bin/
|
129
|
-
- bin/
|
130
|
-
-
|
131
|
-
-
|
132
|
-
-
|
133
|
-
-
|
134
|
-
-
|
135
|
-
-
|
136
|
-
-
|
137
|
-
-
|
138
|
-
-
|
141
|
+
- bin/up_ruby
|
142
|
+
- bin/up_ruby_cluster
|
143
|
+
- ext/up_ext/App.h
|
144
|
+
- ext/up_ext/AsyncSocket.h
|
145
|
+
- ext/up_ext/AsyncSocketData.h
|
146
|
+
- ext/up_ext/BloomFilter.h
|
147
|
+
- ext/up_ext/ChunkedEncoding.h
|
148
|
+
- ext/up_ext/ClientApp.h
|
149
|
+
- ext/up_ext/HttpContext.h
|
150
|
+
- ext/up_ext/HttpContextData.h
|
151
|
+
- ext/up_ext/HttpErrors.h
|
152
|
+
- ext/up_ext/HttpParser.h
|
153
|
+
- ext/up_ext/HttpResponse.h
|
154
|
+
- ext/up_ext/HttpResponseData.h
|
155
|
+
- ext/up_ext/HttpRouter.h
|
156
|
+
- ext/up_ext/Loop.h
|
157
|
+
- ext/up_ext/LoopData.h
|
158
|
+
- ext/up_ext/MoveOnlyFunction.h
|
159
|
+
- ext/up_ext/PerMessageDeflate.h
|
160
|
+
- ext/up_ext/ProxyParser.h
|
161
|
+
- ext/up_ext/QueryParser.h
|
162
|
+
- ext/up_ext/TopicTree.h
|
163
|
+
- ext/up_ext/Utilities.h
|
164
|
+
- ext/up_ext/WebSocket.h
|
165
|
+
- ext/up_ext/WebSocketContext.h
|
166
|
+
- ext/up_ext/WebSocketContextData.h
|
167
|
+
- ext/up_ext/WebSocketData.h
|
168
|
+
- ext/up_ext/WebSocketExtensions.h
|
169
|
+
- ext/up_ext/WebSocketHandshake.h
|
170
|
+
- ext/up_ext/WebSocketProtocol.h
|
171
|
+
- ext/up_ext/bsd.c
|
172
|
+
- ext/up_ext/bsd.h
|
173
|
+
- ext/up_ext/context.c
|
174
|
+
- ext/up_ext/epoll_kqueue.c
|
175
|
+
- ext/up_ext/epoll_kqueue.h
|
176
|
+
- ext/up_ext/extconf.rb
|
177
|
+
- ext/up_ext/internal.h
|
178
|
+
- ext/up_ext/libusockets.h
|
179
|
+
- ext/up_ext/libuwebsockets.cpp
|
180
|
+
- ext/up_ext/libuwebsockets.h
|
181
|
+
- ext/up_ext/loop.c
|
182
|
+
- ext/up_ext/loop_data.h
|
183
|
+
- ext/up_ext/socket.c
|
184
|
+
- ext/up_ext/up_ext.c
|
139
185
|
- lib/up/bun/rack_env.rb
|
140
186
|
- lib/up/bun/rack_server.rb
|
141
187
|
- lib/up/bun/server.rb
|
142
188
|
- lib/up/bun/server_cli.rb
|
143
189
|
- lib/up/cli.rb
|
144
|
-
- lib/up/
|
145
|
-
- lib/up/node/cluster_cli.rb
|
146
|
-
- lib/up/node/rack_cluster.rb
|
147
|
-
- lib/up/node/rack_env.rb
|
148
|
-
- lib/up/node/rack_server.rb
|
149
|
-
- lib/up/node/server.rb
|
150
|
-
- lib/up/node/server_cli.rb
|
190
|
+
- lib/up/client.rb
|
151
191
|
- lib/up/rack_builder_patch.rb
|
192
|
+
- lib/up/ruby/cluster.rb
|
193
|
+
- lib/up/ruby/cluster_cli.rb
|
194
|
+
- lib/up/ruby/rack_cluster.rb
|
195
|
+
- lib/up/ruby/rack_server.rb
|
196
|
+
- lib/up/ruby/server_cli.rb
|
152
197
|
- lib/up/u_web_socket/cluster.rb
|
153
198
|
- lib/up/u_web_socket/cluster_cli.rb
|
154
199
|
- lib/up/u_web_socket/rack_cluster.rb
|
155
|
-
- lib/up/u_web_socket/rack_env.rb
|
156
200
|
- lib/up/u_web_socket/rack_server.rb
|
157
201
|
- lib/up/u_web_socket/server.rb
|
158
202
|
- lib/up/u_web_socket/server_cli.rb
|
159
203
|
- lib/up/version.rb
|
160
|
-
- opal-up.gemspec
|
161
|
-
- up_logo.svg
|
162
204
|
homepage: ''
|
163
205
|
licenses:
|
164
206
|
- MIT
|
@@ -171,7 +213,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
171
213
|
requirements:
|
172
214
|
- - ">="
|
173
215
|
- !ruby/object:Gem::Version
|
174
|
-
version:
|
216
|
+
version: 3.0.0
|
175
217
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
176
218
|
requirements:
|
177
219
|
- - ">="
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/bin/up_node
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
if RUBY_ENGINE == 'opal'
|
4
|
-
require 'up/node/server_cli'
|
5
|
-
Up::CLI.call
|
6
|
-
else
|
7
|
-
require 'up/cli'
|
8
|
-
Up::CLI.setup_node
|
9
|
-
lib_dir = File.expand_path("#{__dir__}/../lib")
|
10
|
-
gems = Up::CLI.get_gems_for_cmd
|
11
|
-
Kernel.exec("opal -Rnodejs -E -I. -I#{lib_dir} -g rack #{gems} #{__FILE__} -- #{ARGV.join(' ')}")
|
12
|
-
end
|
data/bin/up_node_cluster
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
if RUBY_ENGINE == 'opal'
|
4
|
-
require 'up/node/cluster_cli'
|
5
|
-
Up::CLI.call
|
6
|
-
else
|
7
|
-
require 'up/cli'
|
8
|
-
Up::CLI.setup_node
|
9
|
-
lib_dir = File.expand_path("#{__dir__}/../lib")
|
10
|
-
gems = Up::CLI.get_gems_for_cmd
|
11
|
-
Kernel.exec("opal -Rnodejs -E -I. -I#{lib_dir} -g rack #{gems} #{__FILE__} -- #{ARGV.join(' ')}")
|
12
|
-
end
|
data/example_rack_app/Gemfile
DELETED
data/example_rack_app/config.ru
DELETED
data/example_roda_app/Gemfile
DELETED
data/example_roda_app/config.ru
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require "roda"
|
2
|
-
|
3
|
-
class RodaApp < Roda
|
4
|
-
STDERR.puts "executing route"
|
5
|
-
route do |r|
|
6
|
-
STDERR.puts r
|
7
|
-
# GET / request
|
8
|
-
r.root do
|
9
|
-
r.redirect "/hello"
|
10
|
-
end
|
11
|
-
|
12
|
-
# /hello branch
|
13
|
-
r.on "hello" do
|
14
|
-
# Set variable for all routes in /hello branch
|
15
|
-
@greeting = 'Hello'
|
16
|
-
|
17
|
-
# GET /hello/world request
|
18
|
-
r.get "world" do
|
19
|
-
"#{@greeting} world!"
|
20
|
-
end
|
21
|
-
|
22
|
-
# /hello request
|
23
|
-
r.is do
|
24
|
-
# GET /hello request
|
25
|
-
r.get do
|
26
|
-
"#{@greeting}!"
|
27
|
-
end
|
28
|
-
|
29
|
-
# POST /hello request
|
30
|
-
r.post do
|
31
|
-
puts "Someone said #{@greeting}!"
|
32
|
-
r.redirect
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/example_sinatra_app/Gemfile
DELETED
data/lib/up/node/cluster.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# backtick_javascript: true
|
2
|
-
require 'up/node/server'
|
3
|
-
|
4
|
-
%x{
|
5
|
-
const cluster = require('node:cluster');
|
6
|
-
const num_workers = require('node:os').availableParallelism();
|
7
|
-
}
|
8
|
-
|
9
|
-
module Up
|
10
|
-
module Node
|
11
|
-
class Cluster < Up::Node::Server
|
12
|
-
def initialize(app:, host: 'localhost', port: 3000, scheme: 'http', ca_file: nil, cert_file: nil, key_file: nil, workers: nil)
|
13
|
-
super(app: app, host: host, port: port, scheme: scheme, ca_file: ca_file, cert_file: cert_file, key_file: key_file)
|
14
|
-
@workers = workers || `num_workers`
|
15
|
-
@members = []
|
16
|
-
end
|
17
|
-
|
18
|
-
def listen
|
19
|
-
raise "already running" unless @members.empty?
|
20
|
-
%x{
|
21
|
-
if (cluster.isPrimary) {
|
22
|
-
for (let i = 0; i < #@workers; i++) {
|
23
|
-
#@members.push(cluster.fork());
|
24
|
-
}
|
25
|
-
} else {
|
26
|
-
#{super}
|
27
|
-
}
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
def stop
|
32
|
-
if Up::CLI::stoppable?
|
33
|
-
@members.each { |m| `m.kill()` }
|
34
|
-
@members.clear
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/lib/up/node/cluster_cli.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'opal/platform'
|
2
|
-
require 'nodejs/file'
|
3
|
-
require 'nodejs/require'
|
4
|
-
require 'opal-parser'
|
5
|
-
require 'rack/builder'
|
6
|
-
require 'up/rack_builder_patch'
|
7
|
-
require 'up/node/rack_cluster'
|
8
|
-
|
9
|
-
module Up
|
10
|
-
module CLI
|
11
|
-
def self.call
|
12
|
-
Up::Node::RackCluster.run(get_app, get_options)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
data/lib/up/node/rack_env.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
# backtick_javascript: true
|
2
|
-
|
3
|
-
require 'logger'
|
4
|
-
require 'up/version'
|
5
|
-
|
6
|
-
module Up
|
7
|
-
module Node
|
8
|
-
class RackEnv < ::Hash
|
9
|
-
RACK_VARS = %w[rack.errors rack.hijack rack.hijack? rack.input rack.logger
|
10
|
-
rack.multipart.buffer_size rack.multipart.tempfile_factory
|
11
|
-
rack.response_finished
|
12
|
-
rack.session rack.upgrade rack.upgrade? rack.url_scheme
|
13
|
-
HTTP_ACCEPT HTTP_ACCEPT_ENCODING HTTP_ACCEPT_LANGUAGE
|
14
|
-
HTTP_CONNECTION HTTP_HOST HTTP_USER_AGENT HTTP_VERSION PATH_INFO QUERY_STRING REQUEST_METHOD
|
15
|
-
SCRIPT_NAME SERVER_NAME SERVER_PROTOCOL SERVER_SOFTWARE]
|
16
|
-
def initialize(req, config)
|
17
|
-
@req = req
|
18
|
-
@config = config
|
19
|
-
end
|
20
|
-
|
21
|
-
def [](key)
|
22
|
-
return super(key) if key?(key)
|
23
|
-
self[key] = case key
|
24
|
-
when 'rack.errors'
|
25
|
-
STDERR
|
26
|
-
when 'rack.hijack'
|
27
|
-
nil
|
28
|
-
when 'rack.hijack?'
|
29
|
-
false
|
30
|
-
when 'rack.input'
|
31
|
-
::IO.new
|
32
|
-
when 'rack.logger'
|
33
|
-
::Logger.new(self['rack.errors'])
|
34
|
-
when 'rack.multipart.buffer_size'
|
35
|
-
4096
|
36
|
-
when 'rack.multipart.tempfile_factory'
|
37
|
-
proc { |_filename, _content_type| File.new }
|
38
|
-
when 'rack.response_finished'
|
39
|
-
[]
|
40
|
-
when 'rack.session'
|
41
|
-
{}
|
42
|
-
when 'rack.upgrade'
|
43
|
-
nil
|
44
|
-
when 'rack.upgrade?'
|
45
|
-
nil
|
46
|
-
when 'rack.url_scheme'
|
47
|
-
@config[:scheme]
|
48
|
-
when 'HTTP_VERSION'
|
49
|
-
`#@reg.httpVersion`
|
50
|
-
when 'PATH_INFO'
|
51
|
-
`#@req.url`
|
52
|
-
when 'QUERY_STRING'
|
53
|
-
""
|
54
|
-
when 'RACK_ERRORS'
|
55
|
-
self['rack.errors']
|
56
|
-
when 'RACK_LOGGER'
|
57
|
-
self['rack.logger']
|
58
|
-
when 'REQUEST_METHOD'
|
59
|
-
`#@req.method`
|
60
|
-
when 'SCRIPT_NAME'
|
61
|
-
""
|
62
|
-
when 'SERVER_NAME'
|
63
|
-
@config[:host]
|
64
|
-
when 'SERVER_PORT'
|
65
|
-
@config[:port].to_s
|
66
|
-
when 'SERVER_PROTOCOL'
|
67
|
-
""
|
68
|
-
when 'SERVER_SOFTWARE'
|
69
|
-
"#{@config[:handler]}/#{Up::VERSION} #{@config[:engine]}"
|
70
|
-
else
|
71
|
-
if key.start_with?('HTTP_')
|
72
|
-
key = key[5..].gsub(/_/, '-')
|
73
|
-
`#@req.headers[key.toLowerCase()]`
|
74
|
-
else
|
75
|
-
nil
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def req_headers
|
81
|
-
h = {}
|
82
|
-
%x{
|
83
|
-
var hdr, hds = #@req.headers;
|
84
|
-
for (hdr in hds) { h.set(hdr, hdrs[hdr]); }
|
85
|
-
}
|
86
|
-
h
|
87
|
-
end
|
88
|
-
|
89
|
-
def each
|
90
|
-
unless @got_them_all
|
91
|
-
RACK_VARS.each { |k| self[k] unless self.key?(k) }
|
92
|
-
@got_them_all = true
|
93
|
-
end
|
94
|
-
super
|
95
|
-
end
|
96
|
-
|
97
|
-
def to_s
|
98
|
-
unless @got_them_all
|
99
|
-
RACK_VARS.each { |k| self[k] unless self.key?(k) }
|
100
|
-
@got_them_all = true
|
101
|
-
end
|
102
|
-
super
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
data/lib/up/node/server.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
# backtick_javascript: true
|
2
|
-
require 'up/cli'
|
3
|
-
require 'up/node/rack_env'
|
4
|
-
|
5
|
-
%x{
|
6
|
-
module.paths.push(process.cwd() + '/node_modules');
|
7
|
-
const http = require('node:http');
|
8
|
-
const https = require('node:https');
|
9
|
-
const fs = require('node:fs');
|
10
|
-
}
|
11
|
-
|
12
|
-
module Up
|
13
|
-
module Node
|
14
|
-
class Server
|
15
|
-
def initialize(app:, host: 'localhost', port: 3000, scheme: 'http', ca_file: nil, cert_file: nil, key_file: nil)
|
16
|
-
@app = app
|
17
|
-
@scheme = scheme || 'http'
|
18
|
-
raise "unsupported scheme #{@scheme}" unless %w[http https].include?(@scheme)
|
19
|
-
@host = host || 'localhost'
|
20
|
-
@port = port&.to_i || 3000
|
21
|
-
@config = { handler: self.class.name, engine: "node/#{`process.version`}", port: port, scheme: scheme, host: host }.freeze
|
22
|
-
@ca_file = ca_file
|
23
|
-
@cert_file = cert_file
|
24
|
-
@key_file = key_file
|
25
|
-
@server = nil
|
26
|
-
end
|
27
|
-
|
28
|
-
%x{
|
29
|
-
self.handle_headers = function(rack_headers, srv_res) {
|
30
|
-
if (rack_headers.$$is_hash) {
|
31
|
-
var header, k, v;
|
32
|
-
for(header of rack_headers) {
|
33
|
-
k = header[0];
|
34
|
-
if (!k.startsWith('rack.')) {
|
35
|
-
v = header[1];
|
36
|
-
if (v.$$is_array) {
|
37
|
-
v = v.join("\n");
|
38
|
-
}
|
39
|
-
srv_res.setHeader(k, v);
|
40
|
-
}
|
41
|
-
}
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
self.handle_response = function(parts, srv_res) {
|
46
|
-
if (parts["$respond_to?"]('each')) {
|
47
|
-
#{`parts`.each { |part| `srv_res.write(part)` }}
|
48
|
-
} else if (parts["$respond_to?"]('call')) {
|
49
|
-
srv_res.write(parts.$call());
|
50
|
-
}
|
51
|
-
#{`parts`.close if `parts`.respond_to?(:close)}
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
def listen
|
56
|
-
raise "already running" if @server
|
57
|
-
%x{
|
58
|
-
const ounr = Opal.Up.Node.RackEnv;
|
59
|
-
const ouns = Opal.Up.Node.Server;
|
60
|
-
function handler(req, res) {
|
61
|
-
const rack_res = #@app.$call(ounr.$new(req, #@config));
|
62
|
-
res.statusCode = rack_res[0];
|
63
|
-
ouns.handle_headers(rack_res[1], res);
|
64
|
-
ouns.handle_response(rack_res[2], res);
|
65
|
-
res.end();
|
66
|
-
}
|
67
|
-
if (#@scheme == 'https') {
|
68
|
-
#@server = https.createServer({ ca: fs.readFileSync(#@ca_file), cert: fs.readFileSync(#@cert_file), key: fs.readFileSync(#@key_file) }, handler);
|
69
|
-
} else {
|
70
|
-
#@server = http.createServer(handler);
|
71
|
-
}
|
72
|
-
#@server.listen(#@port, #@host, () => { console.log(`Server is running on ${#@scheme}://${#@host}:${#@port}`)});
|
73
|
-
}
|
74
|
-
end
|
75
|
-
|
76
|
-
def stop
|
77
|
-
if Up::CLI::stoppable?
|
78
|
-
`#@server.close()`
|
79
|
-
@server = nil
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
data/lib/up/node/server_cli.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'opal/platform'
|
2
|
-
require 'nodejs/file'
|
3
|
-
require 'nodejs/require'
|
4
|
-
require 'opal-parser'
|
5
|
-
require 'rack/builder'
|
6
|
-
require 'up/rack_builder_patch'
|
7
|
-
require 'up/node/rack_server'
|
8
|
-
|
9
|
-
module Up
|
10
|
-
module CLI
|
11
|
-
def self.call
|
12
|
-
Up::Node::RackServer.run(get_app, get_options)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
# backtick_javascript: true
|
2
|
-
|
3
|
-
require 'logger'
|
4
|
-
require 'up/version'
|
5
|
-
|
6
|
-
module Up
|
7
|
-
module UWebSocket
|
8
|
-
class RackEnv < ::Hash
|
9
|
-
RACK_VARS = %w[rack.errors rack.hijack rack.hijack? rack.input rack.logger
|
10
|
-
rack.multipart.buffer_size rack.multipart.tempfile_factory
|
11
|
-
rack.response_finished
|
12
|
-
rack.session rack.upgrade rack.upgrade? rack.url_scheme
|
13
|
-
HTTP_ACCEPT HTTP_ACCEPT_ENCODING HTTP_ACCEPT_LANGUAGE
|
14
|
-
HTTP_CONNECTION HTTP_HOST HTTP_USER_AGENT PATH_INFO QUERY_STRING REQUEST_METHOD
|
15
|
-
SCRIPT_NAME SERVER_NAME SERVER_PROTOCOL SERVER_SOFTWARE]
|
16
|
-
def initialize(req, config)
|
17
|
-
@req = req
|
18
|
-
@config = config
|
19
|
-
end
|
20
|
-
|
21
|
-
def [](key)
|
22
|
-
return super(key) if key?(key)
|
23
|
-
self[key] = case key
|
24
|
-
when 'rack.errors'
|
25
|
-
STDERR
|
26
|
-
when 'rack.hijack'
|
27
|
-
nil
|
28
|
-
when 'rack.hijack?'
|
29
|
-
false
|
30
|
-
when 'rack.input'
|
31
|
-
::IO.new
|
32
|
-
when 'rack.logger'
|
33
|
-
::Logger.new(self['rack.errors'])
|
34
|
-
when 'rack.multipart.buffer_size'
|
35
|
-
4096
|
36
|
-
when 'rack.multipart.tempfile_factory'
|
37
|
-
proc { |_filename, _content_type| File.new }
|
38
|
-
when 'rack.response_finished'
|
39
|
-
[]
|
40
|
-
when 'rack.session'
|
41
|
-
{}
|
42
|
-
when 'rack.upgrade'
|
43
|
-
nil
|
44
|
-
when 'rack.upgrade?'
|
45
|
-
nil
|
46
|
-
when 'rack.url_scheme'
|
47
|
-
@config[:scheme]
|
48
|
-
when 'PATH_INFO'
|
49
|
-
`#@req.getUrl()`
|
50
|
-
when 'QUERY_STRING'
|
51
|
-
`#@req.getQuery()`
|
52
|
-
when 'RACK_ERRORS'
|
53
|
-
self['rack.errors']
|
54
|
-
when 'RACK_LOGGER'
|
55
|
-
self['rack.logger']
|
56
|
-
when 'REQUEST_METHOD'
|
57
|
-
`#@req.getMethod().toUpperCase()`
|
58
|
-
when 'SCRIPT_NAME'
|
59
|
-
""
|
60
|
-
when 'SERVER_NAME'
|
61
|
-
@config[:host]
|
62
|
-
when 'SERVER_PORT'
|
63
|
-
@config[:port].to_s
|
64
|
-
when 'SERVER_PROTOCOL'
|
65
|
-
`#@req.getHeader('protocol')`
|
66
|
-
when 'SERVER_SOFTWARE'
|
67
|
-
"#{@config[:handler]}/#{Up::VERSION} #{@config[:engine]}"
|
68
|
-
else
|
69
|
-
if key.start_with?('HTTP_')
|
70
|
-
key = key[5..].gsub(/_/, '-')
|
71
|
-
`#@req.getHeader(key.toLowerCase())`
|
72
|
-
else
|
73
|
-
nil
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def req_headers
|
79
|
-
h = {}
|
80
|
-
`#@req.forEach((k, v) => { h.set(k, v); })`
|
81
|
-
h
|
82
|
-
end
|
83
|
-
|
84
|
-
def each
|
85
|
-
unless @got_them_all
|
86
|
-
RACK_VARS.each { |k| self[k] unless self.key?(k) }
|
87
|
-
@got_them_all = true
|
88
|
-
end
|
89
|
-
super
|
90
|
-
end
|
91
|
-
|
92
|
-
def to_s
|
93
|
-
unless @got_them_all
|
94
|
-
RACK_VARS.each { |k| self[k] unless self.key?(k) }
|
95
|
-
@got_them_all = true
|
96
|
-
end
|
97
|
-
super
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|