bridgetown-core 1.2.0 → 1.3.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/bridgetown-core.gemspec +21 -22
  3. data/lib/bridgetown-core/collection.rb +1 -1
  4. data/lib/bridgetown-core/commands/build.rb +3 -0
  5. data/lib/bridgetown-core/commands/console.rb +0 -1
  6. data/lib/bridgetown-core/commands/esbuild/esbuild.config.js +12 -2
  7. data/lib/bridgetown-core/commands/esbuild/esbuild.defaults.js.erb +64 -18
  8. data/lib/bridgetown-core/commands/esbuild/jsconfig.json +10 -0
  9. data/lib/bridgetown-core/commands/esbuild/setup.rb +1 -0
  10. data/lib/bridgetown-core/commands/esbuild/update.rb +3 -0
  11. data/lib/bridgetown-core/commands/new.rb +2 -0
  12. data/lib/bridgetown-core/configuration/configuration_dsl.rb +1 -1
  13. data/lib/bridgetown-core/configuration.rb +13 -12
  14. data/lib/bridgetown-core/configurations/is-land.rb +15 -0
  15. data/lib/bridgetown-core/configurations/lit/lit-components-entry.js +1 -1
  16. data/lib/bridgetown-core/configurations/lit.rb +9 -54
  17. data/lib/bridgetown-core/configurations/purgecss.rb +1 -1
  18. data/lib/bridgetown-core/configurations/ruby2js/ruby2js.rb +10 -0
  19. data/lib/bridgetown-core/configurations/ruby2js.rb +12 -40
  20. data/lib/bridgetown-core/configurations/turbo.rb +17 -7
  21. data/lib/bridgetown-core/errors.rb +10 -1
  22. data/lib/bridgetown-core/filters/localization_filters.rb +11 -0
  23. data/lib/bridgetown-core/helpers.rb +34 -0
  24. data/lib/bridgetown-core/plugin_manager.rb +0 -24
  25. data/lib/bridgetown-core/rack/boot.rb +13 -1
  26. data/lib/bridgetown-core/rack/routes.rb +40 -6
  27. data/lib/bridgetown-core/readers/layout_reader.rb +2 -2
  28. data/lib/bridgetown-core/tags/dsd.rb +15 -0
  29. data/lib/bridgetown-core/tags/l.rb +14 -0
  30. data/lib/bridgetown-core/utils/aux.rb +2 -0
  31. data/lib/bridgetown-core/utils/loaders_manager.rb +7 -0
  32. data/lib/bridgetown-core/utils.rb +52 -5
  33. data/lib/bridgetown-core/version.rb +2 -2
  34. data/lib/bridgetown-core/watcher.rb +15 -8
  35. data/lib/bridgetown-core.rb +12 -0
  36. data/lib/roda/plugins/bridgetown_server.rb +140 -0
  37. data/lib/site_template/Gemfile.erb +6 -3
  38. data/lib/site_template/frontend/javascript/index.js.erb +10 -1
  39. data/lib/site_template/package.json.erb +6 -6
  40. data/lib/site_template/server/roda_app.rb +4 -2
  41. data/lib/site_template/src/_posts/0000-00-00-welcome-to-bridgetown.md.erb +1 -1
  42. metadata +16 -27
  43. data/lib/bridgetown-core/commands/serve/servlet.rb +0 -68
  44. data/lib/bridgetown-core/commands/serve.rb +0 -253
  45. data/lib/bridgetown-core/rack/roda.rb +0 -157
  46. data/lib/roda/plugins/bridgetown_boot.rb +0 -25
@@ -24,10 +24,13 @@ gem "bridgetown", "~> <%= Bridgetown::VERSION %>"
24
24
  # Uncomment to add file-based dynamic routing to your project:
25
25
  # gem "bridgetown-routes", "~> <%= Bridgetown::VERSION %>"
26
26
 
27
+ # Puma is the Rack-compatible web server used by Bridgetown
28
+ # (you can optionally limit this to the "development" group)
29
+ gem "puma", "< 7"
30
+
27
31
  # Uncomment to use the Inspectors API to manipulate the output
28
32
  # of your HTML or XML resources:
29
33
  # gem "nokogiri", "~> 1.13"
30
34
 
31
- # Puma is a Rack-compatible server used by Bridgetown
32
- # (you can optionally limit this to the "development" group)
33
- gem "puma", "~> 5.6"
35
+ # Or for faster parsing of HTML-only resources via Inspectors, use Nokolexbor:
36
+ # gem "nokolexbor", "~> 0.4"
@@ -1,13 +1,22 @@
1
+ <%- if frontend_bundling_option == "esbuild" -%>
2
+ <%- if postcss_option -%>
3
+ import "$styles/index.css"
4
+ <%- else -%>
5
+ import "$styles/index.scss"
6
+ <%- end -%>
7
+ import "$styles/syntax-highlighting.css"
8
+ <%- else -%>
1
9
  <%- if postcss_option -%>
2
10
  import "index.css"
3
11
  <%- else -%>
4
12
  import "index.scss"
5
13
  <%- end -%>
6
14
  import "syntax-highlighting.css"
15
+ <%- end -%>
7
16
 
8
17
  // Import all JavaScript & CSS files from src/_components
9
18
  <%- if frontend_bundling_option == "esbuild" -%>
10
- import components from "bridgetownComponents/**/*.{js,jsx,js.rb,css}"
19
+ import components from "$components/**/*.{js,jsx,js.rb,css}"
11
20
  <%- else -%>
12
21
  const componentsContext = require.context("bridgetownComponents", true, /\.(js|css)$/)
13
22
  componentsContext.keys().forEach(componentsContext)
@@ -15,29 +15,29 @@
15
15
  <%- if frontend_bundling_option == "webpack" -%>
16
16
  "css-loader": "^6.7.1",
17
17
  <%- end -%>
18
- "esbuild": "^0.15.12",
18
+ "esbuild": "^0.17.19",
19
19
  <%- if frontend_bundling_option == "webpack" -%>
20
20
  "esbuild-loader": "^2.18.0",
21
21
  "mini-css-extract-plugin": "^2.6.0",
22
22
  <%- else -%>
23
- "glob": "^8.0.1",
23
+ "glob": "^10.2.6",
24
24
  <%- end -%>
25
25
  <%- unless disable_postcss? -%>
26
- "postcss": "^8.4.12",
26
+ "postcss": "^8.4.23",
27
27
  "postcss-flexbugs-fixes": "^5.0.2",
28
28
  <%- if frontend_bundling_option == "esbuild" -%>
29
- "postcss-import": "^14.1.0",
29
+ "postcss-import": "^15.1.0",
30
30
  "postcss-load-config": "^4.0.1",
31
31
  <%- else -%>
32
32
  "postcss-loader": "^6.2.1",
33
33
  <%- end -%>
34
- "postcss-preset-env": "^7.4.3",
34
+ "postcss-preset-env": "^8.4.1",
35
35
  <%- if frontend_bundling_option == "esbuild" -%>
36
36
  "read-cache": "^1.0.0"<%= "," unless postcss_option %>
37
37
  <%- end -%>
38
38
  <%- end -%>
39
39
  <%- unless postcss_option -%>
40
- "sass": "^1.50.1",
40
+ "sass": "^1.62.1",
41
41
  "sass-loader": "^12.6.0"<%= "," if frontend_bundling_option == "webpack" %>
42
42
  <%- end -%>
43
43
  <%- if frontend_bundling_option == "webpack" -%>
@@ -2,9 +2,11 @@
2
2
  # on the concept of a routing tree. Bridgetown uses it for its development
3
3
  # server, but you can also run it in production for fast, dynamic applications.
4
4
  #
5
- # Learn more at: http://roda.jeremyevans.net
5
+ # Learn more at: https://www.bridgetownrb.com/docs/routes
6
+
7
+ class RodaApp < Roda
8
+ plugin :bridgetown_server
6
9
 
7
- class RodaApp < Bridgetown::Rack::Roda
8
10
  # Some Roda configuration is handled in the `config/initializers.rb` file.
9
11
  # But you can also add additional Roda configuration here if needed.
10
12
 
@@ -5,7 +5,7 @@ date: <%= Time.now.strftime('%Y-%m-%d %H:%M:%S %z') %>
5
5
  categories: updates
6
6
  ---
7
7
 
8
- You’ll find this post in your `_posts` directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run `bridgetown serve`, which launches a web server and auto-regenerates your site when a file is updated.
8
+ You’ll find this post in your `_posts` directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run `bin/bridgetown start`, which launches a web server and auto-regenerates your site when a file is updated.
9
9
 
10
10
  Bridgetown requires blog post files to be named according to the following format:
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridgetown-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-25 00:00:00.000000000 Z
11
+ date: 2023-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -112,28 +112,28 @@ dependencies:
112
112
  requirements:
113
113
  - - "~>"
114
114
  - !ruby/object:Gem::Version
115
- version: '1.0'
115
+ version: '2.0'
116
116
  type: :runtime
117
117
  prerelease: false
118
118
  version_requirements: !ruby/object:Gem::Requirement
119
119
  requirements:
120
120
  - - "~>"
121
121
  - !ruby/object:Gem::Version
122
- version: '1.0'
122
+ version: '2.0'
123
123
  - !ruby/object:Gem::Dependency
124
- name: faraday_middleware
124
+ name: faraday-follow_redirects
125
125
  requirement: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: '1.0'
129
+ version: '0.3'
130
130
  type: :runtime
131
131
  prerelease: false
132
132
  version_requirements: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - "~>"
135
135
  - !ruby/object:Gem::Version
136
- version: '1.0'
136
+ version: '0.3'
137
137
  - !ruby/object:Gem::Dependency
138
138
  name: hash_with_dot_access
139
139
  requirement: !ruby/object:Gem::Requirement
@@ -302,20 +302,6 @@ dependencies:
302
302
  - - "~>"
303
303
  - !ruby/object:Gem::Version
304
304
  version: '2.0'
305
- - !ruby/object:Gem::Dependency
306
- name: webrick
307
- requirement: !ruby/object:Gem::Requirement
308
- requirements:
309
- - - "~>"
310
- - !ruby/object:Gem::Version
311
- version: '1.7'
312
- type: :runtime
313
- prerelease: false
314
- version_requirements: !ruby/object:Gem::Requirement
315
- requirements:
316
- - - "~>"
317
- - !ruby/object:Gem::Version
318
- version: '1.7'
319
305
  - !ruby/object:Gem::Dependency
320
306
  name: zeitwerk
321
307
  requirement: !ruby/object:Gem::Requirement
@@ -362,14 +348,13 @@ files:
362
348
  - lib/bridgetown-core/commands/esbuild.rb
363
349
  - lib/bridgetown-core/commands/esbuild/esbuild.config.js
364
350
  - lib/bridgetown-core/commands/esbuild/esbuild.defaults.js.erb
351
+ - lib/bridgetown-core/commands/esbuild/jsconfig.json
365
352
  - lib/bridgetown-core/commands/esbuild/migrate-from-webpack.rb
366
353
  - lib/bridgetown-core/commands/esbuild/setup.rb
367
354
  - lib/bridgetown-core/commands/esbuild/update.rb
368
355
  - lib/bridgetown-core/commands/new.rb
369
356
  - lib/bridgetown-core/commands/plugins.rb
370
357
  - lib/bridgetown-core/commands/registrations.rb
371
- - lib/bridgetown-core/commands/serve.rb
372
- - lib/bridgetown-core/commands/serve/servlet.rb
373
358
  - lib/bridgetown-core/commands/start.rb
374
359
  - lib/bridgetown-core/commands/webpack.rb
375
360
  - lib/bridgetown-core/commands/webpack/enable-postcss.rb
@@ -408,6 +393,7 @@ files:
408
393
  - lib/bridgetown-core/configurations/cypress/cypress_tasks
409
394
  - lib/bridgetown-core/configurations/gh-pages.rb
410
395
  - lib/bridgetown-core/configurations/gh-pages/gh-pages.yml
396
+ - lib/bridgetown-core/configurations/is-land.rb
411
397
  - lib/bridgetown-core/configurations/lit.rb
412
398
  - lib/bridgetown-core/configurations/lit/esbuild-plugins.js
413
399
  - lib/bridgetown-core/configurations/lit/happy-days.lit.js
@@ -424,6 +410,7 @@ files:
424
410
  - lib/bridgetown-core/configurations/render/render.yaml.erb
425
411
  - lib/bridgetown-core/configurations/ruby2js.rb
426
412
  - lib/bridgetown-core/configurations/ruby2js/hello_world.js.rb
413
+ - lib/bridgetown-core/configurations/ruby2js/ruby2js.rb
427
414
  - lib/bridgetown-core/configurations/shoelace.rb
428
415
  - lib/bridgetown-core/configurations/stimulus.rb
429
416
  - lib/bridgetown-core/configurations/tailwindcss.rb
@@ -460,6 +447,7 @@ files:
460
447
  - lib/bridgetown-core/filters/date_filters.rb
461
448
  - lib/bridgetown-core/filters/from_liquid.rb
462
449
  - lib/bridgetown-core/filters/grouping_filters.rb
450
+ - lib/bridgetown-core/filters/localization_filters.rb
463
451
  - lib/bridgetown-core/filters/translation_filters.rb
464
452
  - lib/bridgetown-core/filters/url_filters.rb
465
453
  - lib/bridgetown-core/frontmatter_defaults.rb
@@ -487,7 +475,6 @@ files:
487
475
  - lib/bridgetown-core/plugin_manager.rb
488
476
  - lib/bridgetown-core/rack/boot.rb
489
477
  - lib/bridgetown-core/rack/logger.rb
490
- - lib/bridgetown-core/rack/roda.rb
491
478
  - lib/bridgetown-core/rack/routes.rb
492
479
  - lib/bridgetown-core/rack/static_indexes.rb
493
480
  - lib/bridgetown-core/reader.rb
@@ -507,8 +494,10 @@ files:
507
494
  - lib/bridgetown-core/static_file.rb
508
495
  - lib/bridgetown-core/tags/asset_path.rb
509
496
  - lib/bridgetown-core/tags/class_map.rb
497
+ - lib/bridgetown-core/tags/dsd.rb
510
498
  - lib/bridgetown-core/tags/find.rb
511
499
  - lib/bridgetown-core/tags/highlight.rb
500
+ - lib/bridgetown-core/tags/l.rb
512
501
  - lib/bridgetown-core/tags/link.rb
513
502
  - lib/bridgetown-core/tags/live_reload_dev_js.rb
514
503
  - lib/bridgetown-core/tags/post_url.rb
@@ -529,7 +518,7 @@ files:
529
518
  - lib/bridgetown-core/version.rb
530
519
  - lib/bridgetown-core/watcher.rb
531
520
  - lib/bridgetown-core/yaml_parser.rb
532
- - lib/roda/plugins/bridgetown_boot.rb
521
+ - lib/roda/plugins/bridgetown_server.rb
533
522
  - lib/roda/plugins/bridgetown_ssr.rb
534
523
  - lib/roda/plugins/initializers.rb
535
524
  - lib/roda/plugins/method_override.rb
@@ -601,9 +590,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
601
590
  version: 2.7.0
602
591
  required_rubygems_version: !ruby/object:Gem::Requirement
603
592
  requirements:
604
- - - ">="
593
+ - - ">"
605
594
  - !ruby/object:Gem::Version
606
- version: '0'
595
+ version: 1.3.1
607
596
  requirements: []
608
597
  rubygems_version: 3.1.4
609
598
  signing_key:
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "webrick"
4
-
5
- module Bridgetown
6
- module Commands
7
- class Serve
8
- class Servlet < WEBrick::HTTPServlet::FileHandler
9
- DEFAULTS = {
10
- "Cache-Control" => "private, max-age=0, proxy-revalidate, " \
11
- "no-store, no-cache, must-revalidate",
12
- }.freeze
13
-
14
- def initialize(server, root, callbacks)
15
- # So we can access them easily.
16
- @bridgetown_opts = server.config[:BridgetownOptions]
17
- set_defaults
18
- super
19
- end
20
-
21
- def search_index_file(req, res)
22
- super ||
23
- search_file(req, res, ".html") ||
24
- search_file(req, res, ".xhtml")
25
- end
26
-
27
- # Add the ability to tap file.html the same way that Nginx does on our
28
- # Docker images (or on GitHub Pages.) The difference is that we might end
29
- # up with a different preference on which comes first.
30
-
31
- def search_file(req, res, basename)
32
- # /file.* > /file/index.html > /file.html
33
- super ||
34
- super(req, res, "#{basename}.html") ||
35
- super(req, res, "#{basename}.xhtml")
36
- end
37
-
38
- # rubocop:disable Naming/MethodName
39
- def do_GET(req, res)
40
- rtn = super
41
-
42
- validate_and_ensure_charset(req, res)
43
- res.header.merge!(@headers)
44
- rtn
45
- end
46
- # rubocop:enable Naming/MethodName
47
-
48
- private
49
-
50
- def validate_and_ensure_charset(_req, res)
51
- key = res.header.keys.grep(%r!content-type!i).first
52
- typ = res.header[key]
53
-
54
- return if %r!;\s*charset=!.match?(typ)
55
-
56
- res.header[key] = "#{typ}; charset=#{@bridgetown_opts["encoding"]}"
57
- end
58
-
59
- def set_defaults
60
- hash_ = @bridgetown_opts.fetch("webrick", {}).fetch("headers", {})
61
- DEFAULTS.each_with_object(@headers = hash_) do |(key, val), hash|
62
- hash[key] = val unless hash.key?(key)
63
- end
64
- end
65
- end
66
- end
67
- end
68
- end
@@ -1,253 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bridgetown
4
- module Commands
5
- class Serve < Thor::Group
6
- extend BuildOptions
7
- extend Summarizable
8
- include ConfigurationOverridable
9
-
10
- Registrations.register do
11
- register(Serve, "serve", "serve", Serve.summary)
12
- end
13
-
14
- class_option :host, aliases: "-H", desc: "Host to bind to"
15
- class_option :port, aliases: "-P", desc: "Port to listen on"
16
- class_option :detach,
17
- aliases: "-B",
18
- type: :boolean,
19
- desc: "Run the server in the background"
20
- class_option :ssl_cert, desc: "X.509 (SSL) certificate."
21
- class_option :ssl_key, desc: "X.509 (SSL) Private Key."
22
- class_option :show_dir_listing,
23
- type: :boolean,
24
- desc: "Show a directory listing instead of loading your index file."
25
- class_option :skip_initial_build,
26
- type: :boolean,
27
- desc: "Skips the initial site build which occurs before the server is started."
28
- class_option :watch,
29
- type: :boolean,
30
- aliases: "-w",
31
- default: true,
32
- desc: "Watch for changes and rebuild"
33
-
34
- def self.banner
35
- "bridgetown serve [options]"
36
- end
37
- summary "DEPRECATED (Serve your site locally using WEBrick)"
38
-
39
- DIRECTORY_INDEX = %w(
40
- index.htm
41
- index.html
42
- index.rhtml
43
- index.xht
44
- index.xhtml
45
- index.cgi
46
- index.xml
47
- index.json
48
- ).freeze
49
-
50
- def serve
51
- Bridgetown::Deprecator.deprecation_message(
52
- "WEBrick (serve) will be removed in favor of Puma (start) in the next Bridgetown release"
53
- )
54
-
55
- @mutex = Mutex.new
56
- @run_cond = ConditionVariable.new
57
- @running = false
58
-
59
- no_watch = options["watch"] == false
60
-
61
- options = Thor::CoreExt::HashWithIndifferentAccess.new(self.options)
62
- options["serving"] = true
63
- options["watch"] = true unless no_watch
64
-
65
- config = configuration_with_overrides(options, Bridgetown::Current.preloaded_configuration)
66
- if Bridgetown.environment == "development"
67
- default_url(config).tap do |url|
68
- options["url"] = url
69
- config.url = url
70
- end
71
- end
72
-
73
- invoke(Build, [], options)
74
- start_server
75
- end
76
-
77
- protected
78
-
79
- def start_server
80
- destination = Bridgetown::Current.preloaded_configuration.destination
81
- setup(destination)
82
-
83
- start_up_webrick(destination)
84
- end
85
-
86
- def setup(destination)
87
- require_relative "serve/servlet"
88
-
89
- FileUtils.mkdir_p(destination)
90
- return unless File.exist?(File.join(destination, "404.html"))
91
-
92
- WEBrick::HTTPResponse.class_eval do
93
- def create_error_page
94
- @header["Content-Type"] = "text/html; charset=UTF-8"
95
- @body = File.read(File.join(@config[:DocumentRoot], "404.html"))
96
- end
97
- end
98
- end
99
-
100
- def webrick_opts(opts)
101
- opts = {
102
- BridgetownOptions: opts,
103
- DoNotReverseLookup: true,
104
- MimeTypes: mime_types,
105
- DocumentRoot: opts["destination"],
106
- StartCallback: start_callback(opts["detach"]),
107
- StopCallback: stop_callback(opts["detach"]),
108
- BindAddress: opts["host"],
109
- Port: opts["port"],
110
- DirectoryIndex: DIRECTORY_INDEX,
111
- }
112
-
113
- opts[:DirectoryIndex] = [] if opts[:BridgetownOptions]["show_dir_listing"]
114
-
115
- enable_ssl(opts)
116
- enable_logging(opts)
117
- opts
118
- end
119
-
120
- def start_up_webrick(destination)
121
- opts = Bridgetown::Current.preloaded_configuration
122
- @server = WEBrick::HTTPServer.new(webrick_opts(opts)).tap { |o| o.unmount("") }
123
- @server.mount(opts["base_path"].to_s, Servlet, destination, file_handler_opts)
124
-
125
- Bridgetown.logger.info "Server address:", server_address(@server, opts)
126
- launch_browser @server, opts if opts["open_url"]
127
- boot_or_detach @server, opts
128
- end
129
-
130
- def shutdown
131
- @server.shutdown if running?
132
- end
133
-
134
- def default_url(config)
135
- format_url(
136
- config["ssl_cert"] && config["ssl_key"],
137
- config["host"] == "127.0.0.1" ? "localhost" : config["host"],
138
- config["port"]
139
- )
140
- end
141
-
142
- def format_url(ssl_enabled, address, port, baseurl = nil)
143
- format("%<prefix>s://%<address>s:%<port>i%<baseurl>s",
144
- prefix: ssl_enabled ? "https" : "http",
145
- address: address,
146
- port: port,
147
- baseurl: baseurl ? "#{baseurl}/" : "")
148
- end
149
-
150
- # Recreate NondisclosureName under utf-8 circumstance
151
- def file_handler_opts
152
- WEBrick::Config::FileHandler.merge(
153
- FancyIndexing: true,
154
- NondisclosureName: [
155
- ".ht*", "~*",
156
- ]
157
- )
158
- end
159
-
160
- def server_address(server, options = {})
161
- format_url(
162
- server.config[:SSLEnable],
163
- server.config[:BindAddress],
164
- server.config[:Port],
165
- options["baseurl"]
166
- )
167
- end
168
-
169
- # Keep in our area with a thread or detach the server as requested
170
- # by the user. This method determines what we do based on what you
171
- # ask us to do.
172
- def boot_or_detach(server, opts)
173
- if opts["detach"]
174
- pid = Process.fork do
175
- server.start
176
- end
177
-
178
- Process.detach(pid)
179
- Bridgetown.logger.info "Server detached with pid '#{pid}'.", \
180
- "Run `pkill -f bridgetown' or `kill -9 #{pid}' " \
181
- "to stop the server."
182
- else
183
- t = Thread.new { server.start }
184
- trap("INT") { server.shutdown }
185
- t.join
186
- end
187
- end
188
-
189
- # Make the stack verbose if the user requests it.
190
- def enable_logging(opts)
191
- opts[:AccessLog] = []
192
- level = WEBrick::Log.const_get(opts[:BridgetownOptions]["verbose"] ? :DEBUG : :WARN)
193
- opts[:Logger] = WEBrick::Log.new($stdout, level)
194
- end
195
-
196
- # Add SSL to the stack if the user triggers --enable-ssl and they
197
- # provide both types of certificates commonly needed. Raise if they
198
- # forget to add one of the certificates.
199
- def enable_ssl(opts)
200
- cert, key, src =
201
- opts[:BridgetownOptions].values_at("ssl_cert", "ssl_key", "source")
202
-
203
- return if cert.nil? && key.nil?
204
- raise "Missing --ssl_cert or --ssl_key. Both are required." unless cert && key
205
-
206
- require "openssl"
207
- require "webrick/https"
208
-
209
- opts[:SSLCertificate] = OpenSSL::X509::Certificate.new(read_file(src, cert))
210
- begin
211
- opts[:SSLPrivateKey] = OpenSSL::PKey::RSA.new(read_file(src, key))
212
- rescue StandardError
213
- raise unless defined?(OpenSSL::PKey::EC)
214
-
215
- opts[:SSLPrivateKey] = OpenSSL::PKey::EC.new(read_file(src, key))
216
- end
217
- opts[:SSLEnable] = true
218
- end
219
-
220
- def start_callback(detached)
221
- return if detached
222
-
223
- proc do
224
- @mutex.synchronize do
225
- @running = true
226
- Bridgetown.logger.info("Server running…", "press ctrl-c to stop.")
227
- @run_cond.broadcast
228
- end
229
- end
230
- end
231
-
232
- def stop_callback(detached)
233
- return if detached
234
-
235
- proc do
236
- @mutex.synchronize do
237
- @running = false
238
- @run_cond.broadcast
239
- end
240
- end
241
- end
242
-
243
- def mime_types
244
- file = File.expand_path("../mime.types", __dir__)
245
- WEBrick::HTTPUtils.load_mime_types(file)
246
- end
247
-
248
- def read_file(source_dir, file_path)
249
- File.read(Bridgetown.sanitized_path(source_dir, file_path))
250
- end
251
- end
252
- end
253
- end