KonnorRogers / snowpacker

A gem to help use Rails with Snowpack
MIT License
70 stars 3 forks source link

Some hacks required to get it work with non-Rails #25

Open katafrakt opened 4 years ago

katafrakt commented 4 years ago

Hey! I'm trying to use Snowpacker with Hanami and I finally managed to get it to work, but I needed to add two hacks to Snowpacker to achieve that. I wonder what would be your ideas for proper fixes.

Hack 1: 304 + Content-Type

When I reload the page and Snowpack server returns 304 (file not changed), Rack complains about it with an exception:

Rack::Lint::LintError: Content-Type header found in 304 response, not allowed
    /home/katafrakt/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/lint.rb:21:in `assert'
    /home/katafrakt/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/lint.rb:710:in `block in check_content_type'
    /home/katafrakt/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/lint.rb:706:in `each'
    /home/katafrakt/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/lint.rb:706:in `check_content_type'
    /home/katafrakt/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/lint.rb:70:in `_call'
    /home/katafrakt/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/lint.rb:38:in `call'
    /home/katafrakt/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/show_exceptions.rb:23:in `call'
    /home/katafrakt/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.3/lib/rack/handler/webrick.rb:95:in `service'
    /home/katafrakt/.rbenv/versions/2.6.6/lib/ruby/2.6.0/webrick/httpserver.rb:140:in `service'
    /home/katafrakt/.rbenv/versions/2.6.6/lib/ruby/2.6.0/webrick/httpserver.rb:96:in `run'
    /home/katafrakt/.rbenv/versions/2.6.6/lib/ruby/2.6.0/webrick/server.rb:307:in `block in start_thread'

I hacked it by modifying proxy.rb and adding this to the end of perform_request:

        re = super(env)
          if re[0] == 304
            re[1].delete('content-type')
          end
        re
      else

Hack 2: /web_modules

I'm trying to use Vue 3 with it. To achieve that I had to reroute /web_modules too in Rack proxy. This hack is in the beginning of perform_requests:

env["PATH_INFO"].gsub!(/^\/web_modules/, "/#{Snowpacker.config.output_path}/web_modules")

I know both of these are stupid, but with that it works, so they can be a starting point to find proper solutions.

Thanks for this project, by the way!

KonnorRogers commented 4 years ago

@katafrakt first of all, really cool that you're trying out Snowpacker. Unfortunately, this gem is also wildly incomplete in its current state. I didn't expect anybody to be using it yet to be honest.

As for fixes, I have never personally used Hanami so I'd have to look into it a little further...I also haven't tested it with SPAs yet...

Like I said this project isn't really ready to be used in its current state, but I do appreciate being made aware of these issues. I'm going to leave this issue open for when I get around to testing it.

katafrakt commented 4 years ago

I think these aren't really Hanami-related, just non-Rails related, and should also happen in Sinatra or Roda. I can check that. For the first issue (304), I suspect that Rails has some extra middleware which fixes it.

Anyway, if you need any help, let me know. Hanami is currently missing any kind of modern frontend stack integration and I think Snowpack looks far more promising than Webpack.

KonnorRogers commented 4 years ago

@katafrakt good to know...I did not realize this was an issue with Hanami. I imagine this also rings true for Sinatra.

As of right now, the Snowpacker development is "halted" because I'm working on a Snowpack plugin to bundle for production which will include a Manifest of assets as well as

I'll definitely let you know should anything come up as to any issues I may need help with.

Thank you again for the feedback and I'll work on making sure these are non-issues in the future!