Module: Jekyll::Vite::Proxy

Defined in:
lib/jekyll/vite/proxy.rb

Overview

Internal: Extend the default servlet to add a Rack-based proxy in order to forward asset requests to the Vite.js development server.

Constant Summary collapse

STATUS_SERVE_ORIGINAL =

Internal: Used to detect proxied requests since it’s not a valid status code.

7

Instance Method Summary collapse

Instance Method Details

#initialize(server, *args) ⇒ Object



13
14
15
16
# File 'lib/jekyll/vite/proxy.rb', line 13

def initialize(server, *args)
  @server = server
  super
end

#service(req, res) ⇒ Object

Override: Detect the special status set by the Proxy Servlet and use the default Jekyll response instead.



29
30
31
32
33
34
35
# File 'lib/jekyll/vite/proxy.rb', line 29

def service(req, res)
  proxy_servlet.service(req, res)
  if res.status == STATUS_SERVE_ORIGINAL
    res.status = 200
    super
  end
end

#set_filename(req, res) ⇒ Object

Override: Serve compiled Vite assets from the temporary folder as needed.



19
20
21
22
23
24
25
# File 'lib/jekyll/vite/proxy.rb', line 19

def set_filename(req, res)
  original_root = @root.dup
  if req.path_info.start_with?("/#{ ViteRuby.config.public_output_dir }/")
    @root = ViteRuby.config.root.join(ViteRuby.config.public_dir)
  end
  super.tap { @root = original_root }
end