@vercel/ruby 2.2.1 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +618 -192
- package/package.json +4 -3
- package/vc_init_dev.rb +83 -0
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/ruby",
|
|
3
3
|
"author": "Nathan Cahill <nathan@nathancahill.com>",
|
|
4
|
-
"version": "2.2.
|
|
4
|
+
"version": "2.2.2",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index",
|
|
7
7
|
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/ruby",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
|
-
"vc_init.rb"
|
|
10
|
+
"vc_init.rb",
|
|
11
|
+
"vc_init_dev.rb"
|
|
11
12
|
],
|
|
12
13
|
"repository": {
|
|
13
14
|
"type": "git",
|
|
@@ -18,7 +19,7 @@
|
|
|
18
19
|
"@types/fs-extra": "8.0.0",
|
|
19
20
|
"@types/semver": "6.0.0",
|
|
20
21
|
"@types/which": "3.0.0",
|
|
21
|
-
"@vercel/build-utils": "
|
|
22
|
+
"@vercel/build-utils": "13.0.1",
|
|
22
23
|
"execa": "2.0.4",
|
|
23
24
|
"fs-extra": "^7.0.1",
|
|
24
25
|
"jest-junit": "16.0.0",
|
package/vc_init_dev.rb
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Auto-generated template used by vercel dev (Ruby, Rack)
|
|
3
|
+
Serves static files from PUBLIC_DIR before delegating to the user Rack app.
|
|
4
|
+
|
|
5
|
+
This file is written to the project at .vercel/ruby/vc_init_dev.rb
|
|
6
|
+
and executed by the dev server launcher.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
require 'rack'
|
|
10
|
+
require 'rack/handler/webrick'
|
|
11
|
+
require 'webrick'
|
|
12
|
+
require 'socket'
|
|
13
|
+
|
|
14
|
+
$stdout.sync = true
|
|
15
|
+
$stderr.sync = true
|
|
16
|
+
|
|
17
|
+
USER_ENTRYPOINT = "__VC_DEV_ENTRYPOINT__"
|
|
18
|
+
PUBLIC_DIR = 'public'
|
|
19
|
+
|
|
20
|
+
def build_user_app
|
|
21
|
+
if USER_ENTRYPOINT.end_with?('.ru')
|
|
22
|
+
app, _ = Rack::Builder.parse_file(USER_ENTRYPOINT)
|
|
23
|
+
app
|
|
24
|
+
else
|
|
25
|
+
# For dev we only support Rack entrypoints (.ru) to ensure consistent behavior
|
|
26
|
+
abort("Unsupported entrypoint: #{USER_ENTRYPOINT}. Please use a Rack config (.ru) file for vercel dev.")
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
class StaticThenApp
|
|
31
|
+
def initialize(app, public_dir)
|
|
32
|
+
@app = app
|
|
33
|
+
@public_dir = public_dir
|
|
34
|
+
@file_server = Rack::File.new(public_dir)
|
|
35
|
+
@base = File.expand_path(public_dir)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def call(env)
|
|
39
|
+
req_path = env['PATH_INFO'] || '/'
|
|
40
|
+
# Normalize path and guard against traversal
|
|
41
|
+
safe = req_path.sub(/^\//, '')
|
|
42
|
+
full = File.expand_path(safe, @base)
|
|
43
|
+
|
|
44
|
+
if full.start_with?(@base + File::SEPARATOR) && File.file?(full)
|
|
45
|
+
# Delegate to Rack::File which handles HEAD/GET correctly
|
|
46
|
+
return @file_server.call(env)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
@app.call(env)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def static_then_app(user_app)
|
|
54
|
+
StaticThenApp.new(user_app, PUBLIC_DIR)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
host = '127.0.0.1'
|
|
58
|
+
begin
|
|
59
|
+
sock = TCPServer.new(host, 0)
|
|
60
|
+
port = sock.addr[1]
|
|
61
|
+
ensure
|
|
62
|
+
sock&.close
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
app = static_then_app(build_user_app)
|
|
66
|
+
|
|
67
|
+
logger = WEBrick::Log.new($stderr)
|
|
68
|
+
logger.level = WEBrick::Log::WARN
|
|
69
|
+
server = WEBrick::HTTPServer.new(
|
|
70
|
+
BindAddress: host,
|
|
71
|
+
Port: port,
|
|
72
|
+
AccessLog: [],
|
|
73
|
+
Logger: logger
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
# Mount the Rack app at root
|
|
77
|
+
server.mount '/', Rack::Handler::WEBrick, app
|
|
78
|
+
|
|
79
|
+
trap('INT') { server.shutdown }
|
|
80
|
+
trap('TERM') { server.shutdown }
|
|
81
|
+
|
|
82
|
+
puts "Serving on http://#{host}:#{server.config[:Port]}"
|
|
83
|
+
server.start
|