Skip to content

Instantly share code, notes, and snippets.

@yefim
Last active December 7, 2022 16:48
Show Gist options
  • Save yefim/7c15db682d3fa128cd9d256f78b65ddc to your computer and use it in GitHub Desktop.
Save yefim/7c15db682d3fa128cd9d256f78b65ddc to your computer and use it in GitHub Desktop.
bundle - bundle exec ruby server.rb - bundle exec ruby cdn.rb -p 4321
require 'sinatra'
get '/cdn.js' do
puts 'cdn was hit'
cache_control :public, max_age: 300
content_type 'text/javascript'
'window.hello = \'world\';'
end
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
# gem "rails"
gem 'sinatra'
gem 'sinatra-contrib'
require 'sinatra'
require 'sinatra/cookies'
set :cookie_options, domain: nil, httponly: false
get '/' do
cookies[:index] = 'true'
%q(
<!DOCTYPE html>
<html>
<body>
<div>
<h1>test</h1>
</div>
<script src="/redirect.js"></script>
<script src="http://localhost:4321/cdn.js"></script>
<script src="/no-redirect.js"></script>
</body>
</html>
)
end
get '/no-redirect.js' do
content_type 'text/javascript'
'console.log(hello); console.log(window.document.cookie)'
end
get '/redirect.js' do
puts 'redirect was hit'
cookies[:redirect] = rand.to_s
redirect 'http://localhost:4321/cdn.js', 302
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment