diff --git a/examples/utopia/.gitignore b/examples/utopia/.gitignore deleted file mode 100644 index c3f534a..0000000 --- a/examples/utopia/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -# Development specific: -/.rspec_status -/.bundle - -# Temporary data should not be added to the repository: -/tmp - -# Node modules are 3rd party dependencies which can be fetched easily: -/node_modules - -# This file should only ever exist on production, and may contain sensitive information: -/config/environment.yaml - -# Ignore resized gallery photos: -/public/_gallery diff --git a/examples/utopia/.rspec b/examples/utopia/.rspec deleted file mode 100644 index 0c705cb..0000000 --- a/examples/utopia/.rspec +++ /dev/null @@ -1,4 +0,0 @@ ---format documentation ---backtrace ---warnings ---require spec_helper diff --git a/examples/utopia/.ruby-version b/examples/utopia/.ruby-version deleted file mode 100644 index ef538c2..0000000 --- a/examples/utopia/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -3.1.2 diff --git a/examples/utopia/Guardfile b/examples/utopia/Guardfile deleted file mode 100644 index 57680af..0000000 --- a/examples/utopia/Guardfile +++ /dev/null @@ -1,29 +0,0 @@ - -group :development do - guard :falcon, port: 9292 do - watch('Gemfile.lock') - watch('config.ru') - watch(%r{^config|lib|pages/.*}) - - notification :off - end -end - -group :test do - guard :rspec, cmd: 'rspec' do - # Notifications can get a bit tedious: - # notification :off - - # Re-run specs if they are changed: - watch(%r{^spec/.+_spec\.rb$}) - watch('spec/spec_helper.rb') {'spec'} - - # Run relevent specs if files in `lib/` or `pages/` are changed: - watch(%r{^lib/(.+)\.rb$}) {|match| "spec/lib/#{match[1]}_spec.rb" } - watch(%r{^pages/(.+)\.(rb|xnode)$}) {|match| "spec/pages/#{match[1]}_spec.rb"} - watch(%r{^pages/(.+)controller\.rb$}) {|match| Dir.glob("spec/pages/#{match[1]}*_spec.rb")} - - # If any files in pages changes, ensure the website still works: - watch(%r{^pages/.*}) {'spec/website_spec.rb'} - end -end diff --git a/examples/utopia/README.md b/examples/utopia/README.md deleted file mode 100644 index 6259113..0000000 --- a/examples/utopia/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# Example WebSocket Chat Server - -This is a simple chat client/server implementation with specs. - -## Starting Development Server - -To start the development server, simply execute - - > rake - Generating transient session key for development... - 20:57:36 - INFO - Starting Falcon HTTP server on localhost:9292 - 20:57:36 - INFO - Guard::RSpec is running - 20:57:36 - INFO - Guard is now watching at '...' - [1] guard(main)> - -Then browse http://localhost:9292 (or as specified) to see your new site. - -## Inspecting with `wscat` - -If you are running a local instance of the server, you can connect to it using `wscat`: - -```bash -$ wscat --ca ~/.localhost/localhost.crt --connect wss://localhost:9292/server/connect -Connected (press CTRL+C to quit) -< {"text":"Hello"} -``` - -Typing text into the web browser broadcasts it to all connected clients, including `wscat`. diff --git a/examples/utopia/bake.rb b/examples/utopia/bake.rb deleted file mode 100644 index 631ae0b..0000000 --- a/examples/utopia/bake.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -# Released under the MIT License. -# Copyright, 2018-2023, by Samuel Williams. - -# Prepare the application for start/restart. -def deploy - # This task is typiclly run after the site is updated but before the server is restarted. -end - -# Restart the application server. -def restart - call 'falcon:supervisor:restart' -end - -# Start the development server. -def default - call 'utopia:development' -end - -def migrate - call 'utopia:environment' - - require 'chat' - - Async do - client = Chat::Database.instance - session = client.session - - result = session.clause("DROP TABLE IF EXISTS").identifier("todo").call - - result = session.clause("CREATE TABLE").identifier("todo") - .clause("(") - .identifier("id").clause("serial PRIMARY KEY,") - .identifier("description").clause("TEXT,") - .identifier("created_at").clause("TIMESTAMP NOT NULL,") - .identifier("completed_at").clause("TIMESTAMP") - .clause(")").call - end -end diff --git a/examples/utopia/config.ru b/examples/utopia/config.ru deleted file mode 100755 index 6ba7d07..0000000 --- a/examples/utopia/config.ru +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env rackup -# frozen_string_literal: true - -require_relative 'config/environment' - -self.freeze_app - -if UTOPIA.production? - # Handle exceptions in production with a error page and send an email notification: - use Utopia::Exceptions::Handler - use Utopia::Exceptions::Mailer -else - # We want to propate exceptions up when running tests: - use Rack::ShowExceptions unless UTOPIA.testing? -end - -# serve static files from public/ -use Utopia::Static, root: 'public' - -use Utopia::Redirection::Rewrite, { - '/' => '/client/index' -} - -use Utopia::Redirection::DirectoryIndex - -use Utopia::Redirection::Errors, { - 404 => '/errors/file-not-found' -} - -require 'utopia/localization' -use Utopia::Localization, - default_locale: 'en', - locales: ['en', 'de', 'ja', 'zh'] - -require 'utopia/session' -use Utopia::Session, - expires_after: 3600 * 24, - secret: UTOPIA.secret_for(:session), - secure: true - -use Utopia::Controller - -# serve static files from pages/ -use Utopia::Static - -# Serve dynamic content -use Utopia::Content - -run lambda { |env| [404, {}, []] } diff --git a/examples/utopia/config/README.md b/examples/utopia/config/README.md deleted file mode 100644 index b5b93b6..0000000 --- a/examples/utopia/config/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Utopia Config - -This directory contains `environment.rb` which is used to initialize the running environment for tasks and servers. - -## Setting Environment Variables - -If you wish to set environment variables on a per-deployment basis, you can do so by creating an `config/environment.yaml` and populating it with key-value pairs. diff --git a/examples/utopia/config/development.yaml b/examples/utopia/config/development.yaml deleted file mode 100644 index a2dc03b..0000000 --- a/examples/utopia/config/development.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -UTOPIA_SESSION_SECRET: a6e955275288042c88d4d89ba1cb631bceb42c2b1d4a3987cdc632ca73208b42a6a592aa16ea3680 diff --git a/examples/utopia/config/environment.rb b/examples/utopia/config/environment.rb deleted file mode 100644 index b1dacfe..0000000 --- a/examples/utopia/config/environment.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -# Released under the MIT License. -# Copyright, 2018-2022, by Samuel Williams. - -require 'bundler/setup' -Bundler.setup - -require 'utopia/setup' -UTOPIA ||= Utopia.setup diff --git a/examples/utopia/config/testing.yaml b/examples/utopia/config/testing.yaml deleted file mode 100644 index 10d102a..0000000 --- a/examples/utopia/config/testing.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -UTOPIA_SESSION_SECRET: '03697dd3148af089cf33fc6c1331cef35a518bd4f693ed54e8fdba8b198784fda27c2b84e115679e' diff --git a/examples/utopia/falcon.rb b/examples/utopia/falcon.rb deleted file mode 100755 index c64153e..0000000 --- a/examples/utopia/falcon.rb +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env -S falcon host -# frozen_string_literal: true - -# Released under the MIT License. -# Copyright, 2020-2022, by Samuel Williams. - -load :rack, :lets_encrypt_tls, :supervisor - -hostname = File.basename(__dir__) -rack hostname, :lets_encrypt_tls - -supervisor diff --git a/examples/utopia/gems.rb b/examples/utopia/gems.rb deleted file mode 100644 index c94e2f3..0000000 --- a/examples/utopia/gems.rb +++ /dev/null @@ -1,43 +0,0 @@ -# frozen_string_literal: true - -# Released under the MIT License. -# Copyright, 2020-2022, by Samuel Williams. - -source 'https://rubygems.org' - -group :preload do - gem 'utopia', '~> 2.20.0' - # gem 'utopia-gallery' - # gem 'utopia-analytics' - - gem 'thread-local' - - gem 'async-redis' - gem 'async-websocket' - - gem 'db' - gem 'db-postgres' - - gem 'variant' -end - -gem 'rake' -gem 'bake' -gem 'bundler' -gem 'rack-test' -gem 'net-smtp' - -group :development do - gem 'guard-falcon', require: false - gem 'guard-rspec', require: false - - gem 'rspec' - gem 'covered' - - gem 'async-rspec' - gem 'benchmark-http' -end - -group :production do - gem 'falcon' -end diff --git a/examples/utopia/lib/chat.rb b/examples/utopia/lib/chat.rb deleted file mode 100644 index 08734f9..0000000 --- a/examples/utopia/lib/chat.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -# Released under the MIT License. -# Copyright, 2020-2022, by Samuel Williams. - -require 'async/redis' - -require 'db/client' -require 'db/postgres' - -require 'thread/local' - -module Chat - module Redis - extend Thread::Local - - def self.local - endpoint = Async::Redis.local_endpoint - client = Async::Redis::Client.new(endpoint) - end - end -end diff --git a/examples/utopia/lib/readme.txt b/examples/utopia/lib/readme.txt deleted file mode 100644 index 43afc24..0000000 --- a/examples/utopia/lib/readme.txt +++ /dev/null @@ -1 +0,0 @@ -You can add additional code for your application in this directory, and require it directly from the config.ru. \ No newline at end of file diff --git a/examples/utopia/pages/_heading.xnode b/examples/utopia/pages/_heading.xnode deleted file mode 100644 index 212185f..0000000 --- a/examples/utopia/pages/_heading.xnode +++ /dev/null @@ -1,2 +0,0 @@ - -

\ No newline at end of file diff --git a/examples/utopia/pages/_page.xnode b/examples/utopia/pages/_page.xnode deleted file mode 100644 index d48ac0d..0000000 --- a/examples/utopia/pages/_page.xnode +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - #{title.gsub(/<.*?>/, "")} - Utopia - - Utopia - - - - - - - - - - - - -
- -
- -
- -
- - \ No newline at end of file diff --git a/examples/utopia/pages/client/client.js b/examples/utopia/pages/client/client.js deleted file mode 100644 index 1c51303..0000000 --- a/examples/utopia/pages/client/client.js +++ /dev/null @@ -1,48 +0,0 @@ - -function connectToChatServer(url) { - console.log("WebSocket Connecting...", url); - var server = new WebSocket(url.href); - - server.onopen = function(event) { - console.log("WebSocket Connected:", server); - chat.disabled = false; - - chat.onkeypress = function(event) { - if (event.keyCode == 13) { - server.send(JSON.stringify({text: chat.value})); - - chat.value = ""; - } - } - }; - - server.onmessage = function(event) { - console.log("WebSocket Message:", event); - - var message = JSON.parse(event.data); - - var pre = document.createElement('pre'); - pre.innerText = message.text; - - response.appendChild(pre); - }; - - server.onerror = function(event) { - console.log("WebSocket Error:", event); - chat.disabled = true; - server.close(); - }; - - server.onclose = function(event) { - console.log("WebSocket Close:", event); - - setTimeout(function() { - connectToChatServer(url); - }, 1000); - }; -} - -var url = new URL('/server/connect', window.location.href); -url.protocol = url.protocol.replace('http', 'ws'); - -connectToChatServer(url); diff --git a/examples/utopia/pages/client/index.xnode b/examples/utopia/pages/client/index.xnode deleted file mode 100644 index 471f4d9..0000000 --- a/examples/utopia/pages/client/index.xnode +++ /dev/null @@ -1,10 +0,0 @@ - - Client (PID: #{Process.pid}) - - -
- -
- -
-
\ No newline at end of file diff --git a/examples/utopia/pages/errors/exception.xnode b/examples/utopia/pages/errors/exception.xnode deleted file mode 100644 index 3d3c1b9..0000000 --- a/examples/utopia/pages/errors/exception.xnode +++ /dev/null @@ -1,5 +0,0 @@ - - Exception - -

It seems like something didn't quite work out as expected!

-
\ No newline at end of file diff --git a/examples/utopia/pages/errors/file-not-found.xnode b/examples/utopia/pages/errors/file-not-found.xnode deleted file mode 100644 index 3d69691..0000000 --- a/examples/utopia/pages/errors/file-not-found.xnode +++ /dev/null @@ -1,5 +0,0 @@ - - File Not Found - -

The file you requested is unfortunately not available at this time!

-
\ No newline at end of file diff --git a/examples/utopia/pages/links.yaml b/examples/utopia/pages/links.yaml deleted file mode 100644 index c399ac4..0000000 --- a/examples/utopia/pages/links.yaml +++ /dev/null @@ -1,2 +0,0 @@ -errors: - display: false diff --git a/examples/utopia/pages/server/controller.rb b/examples/utopia/pages/server/controller.rb deleted file mode 100644 index 7785a56..0000000 --- a/examples/utopia/pages/server/controller.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -# Released under the MIT License. -# Copyright, 2018-2022, by Samuel Williams. - -prepend Actions - -require 'chat' -require 'async/websocket/adapters/rack' - -on 'connect' do |request| - channel = "chat.general" - - response = Async::WebSocket::Adapters::Rack.open(request.env) do |connection| - client = Chat::Redis.instance - - subscription_task = Async do - client.subscribe(channel) do |context| - while true - type, name, message = context.listen - - # The message is text, but contains JSON. - connection.send_text(message) - connection.flush - end - end - end - - while message = connection.read - client.publish(channel, message.buffer) - end - ensure - subscription_task&.stop - end - - respond?(response) -end diff --git a/examples/utopia/public/_static/icon.png b/examples/utopia/public/_static/icon.png deleted file mode 100644 index fd1100a..0000000 Binary files a/examples/utopia/public/_static/icon.png and /dev/null differ diff --git a/examples/utopia/public/_static/site.css b/examples/utopia/public/_static/site.css deleted file mode 100644 index bc55ba7..0000000 --- a/examples/utopia/public/_static/site.css +++ /dev/null @@ -1,213 +0,0 @@ - -html { - font-family: "PT Sans", Verdana, Helvetica, Arial, sans-serif; - font-size: 16px; -} - -pre { - tab-size: 2; -} - -@media (min-width: 40em) { - html { - font-size: 18px; - } - - pre { - tab-size: 4; - } -} - -@media (min-width: 80em) { - html { - font-size: 20px; - } - - pre { - tab-size: 4; - } -} - -body { - padding: 0; - margin: 0; - - background-color: #fafafa; -} - -body > header { - margin: 1rem 0 1rem 0; - - background-color: white; - - background-image: url(utopia-background.svg); - - box-shadow: 0 0 20px rgba(0, 0, 0, 0.1); -} - -body > header img { - display: block; - margin: auto; - height: 4rem; -} - -p, ul, ol { - color: #555; -} - -p strong { - color: #222; -} - -h1, h2, h3, h4, h5, h6 { - margin: 2rem 1rem 1rem 1rem; - color: #4E8DD9; -} - -h1 { - margin-bottom: 4rem; -} - -h2 { - margin-top: 6rem; -} - -img { - border: none; -} - -a { - color: #33a; -} - -a:hover { - color: #55c; -} - -p, ul, ol, dl, h3 { - margin: 2rem; -} - -li { - margin: 0.2rem; -} - -li > ul, li > ol { - margin: 0; -} - -pre { - overflow: auto; - - padding: 1rem 2rem; - font-size: 0.8rem; - - border-top: 1px solid #ccc; - border-bottom: 1px solid #ccc; - - background-color: #eee; -} - -h3 { - border-bottom: 1px solid #ccf; -} - -ul { - margin-bottom: 1rem; -} - -h2, h3, h4, h5, h6 { - font-weight: normal; -} - -body.front h1 { - font-weight: normal; - font-size: 300%; - color: #F89432; - - text-align: center; -} - -footer { - text-align: right; - margin: 2rem; - font-size: 0.65rem; - color: #aaa; -} - -nav { - position: absolute; - margin: 2.5rem; - font-size: 0.8rem; - color: #aaa; -} - -section.input { - margin: 1rem; -} - -section.input input { - width: 100%; -} - -section.features { - display: flex; - flex-wrap: wrap; - justify-content: space-around; - - margin: 1rem; -} - -section.features > div { - box-sizing: border-box; - - flex-basis: 20rem; - flex-grow: 1; - - color: #171e42; - margin: 1rem; - padding: 1rem; - - padding-left: 3rem; - - position: relative; -} - -section.features > div i { - position: absolute; - left: 0rem; - - font-size: 1.5rem; - text-align: center; - - width: 3rem; - color: #fafafa; - text-shadow: 0px 0px 1px #000; -} - -section.features p { - margin: 0; - maring-bottom: 1rem; - font-size: 80%; -} - -section.features h2 { - margin: 0; - font-size: 1.1rem; - padding: 0; -} - -form fieldset { - border: 0; -} - -form fieldset textarea { - box-sizing: border-box; - - width: 100%; - height: 10rem; -} - -form fieldset.footer { - text-align: right; -} diff --git a/examples/utopia/public/_static/utopia-background.svg b/examples/utopia/public/_static/utopia-background.svg deleted file mode 100644 index 6839ef5..0000000 --- a/examples/utopia/public/_static/utopia-background.svg +++ /dev/null @@ -1,11 +0,0 @@ - - - - - \ No newline at end of file diff --git a/examples/utopia/public/_static/utopia.svg b/examples/utopia/public/_static/utopia.svg deleted file mode 100755 index 380ecdb..0000000 --- a/examples/utopia/public/_static/utopia.svg +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/examples/utopia/public/readme.txt b/examples/utopia/public/readme.txt deleted file mode 100644 index e252aa1..0000000 --- a/examples/utopia/public/readme.txt +++ /dev/null @@ -1 +0,0 @@ -This directory is required by Apache/Phusion Passenger and contains static assets that are typically served using sendfile. \ No newline at end of file diff --git a/examples/utopia/spec/spec_helper.rb b/examples/utopia/spec/spec_helper.rb deleted file mode 100644 index 317fe01..0000000 --- a/examples/utopia/spec/spec_helper.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -# Released under the MIT License. -# Copyright, 2018-2022, by Samuel Williams. - -require 'bundler/setup' -require 'covered/rspec' -require 'variant' - -Variant.force!(:testing) - -RSpec.configure do |config| - # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = '.rspec_status' - - config.expect_with :rspec do |c| - c.syntax = :expect - end -end diff --git a/examples/utopia/spec/website_context.rb b/examples/utopia/spec/website_context.rb deleted file mode 100644 index 57c2f1d..0000000 --- a/examples/utopia/spec/website_context.rb +++ /dev/null @@ -1,57 +0,0 @@ -# frozen_string_literal: true - -# Released under the MIT License. -# Copyright, 2018-2022, by Samuel Williams. - -require 'rack/test' -require 'async/rspec/reactor' - -RSpec.shared_context "website" do - include Rack::Test::Methods - - let(:rackup_path) {File.expand_path('../config.ru', __dir__)} - let(:rackup_directory) {File.dirname(rackup_path)} - - let(:app) {Rack::Builder.parse_file(rackup_path).first} -end - -RSpec.shared_examples_for "valid page" do |path| - it "can access #{path}" do - get path - - while last_response.redirect? - follow_redirect! - end - - expect(last_response.status).to be == 200 - end -end - -RSpec.shared_context "server" do - include_context "website" - include_context Async::RSpec::Reactor - - before(:all) do - require 'falcon/server' - require 'async/io/unix_endpoint' - require 'benchmark/http/spider' - end - - before do - @endpoint = Async::HTTP::Endpoint.parse("http://localhost", Async::IO::Endpoint.unix("server.ipc")) - - @server_task = reactor.async do - middleware = Falcon::Server.middleware(app) - - server = Falcon::Server.new(middleware, endpoint) - - server.run - end - end - - after do - @server_task.stop - end - - let(:endpoint) {@endpoint} -end diff --git a/examples/utopia/spec/website_spec.rb b/examples/utopia/spec/website_spec.rb deleted file mode 100644 index a6a08a6..0000000 --- a/examples/utopia/spec/website_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -# Released under the MIT License. -# Copyright, 2018-2022, by Samuel Williams. - -require_relative 'website_context' - -# Learn about best practice specs from http://betterspecs.org -RSpec.describe "website", timeout: 120 do - include_context "server" - - let(:spider) {Benchmark::HTTP::Spider.new(depth: 128)} - let(:statistics) {Benchmark::HTTP::Statistics.new} - - it "should be responsive" do - Async::HTTP::Client.open(endpoint, connection_limit: 8) do |client| - spider.fetch(statistics, client, endpoint.url) do |method, uri, response| - if response.failure? - Console.logger.error{"#{method} #{uri} -> #{response.status}"} - end - end.wait - end - - statistics.print - - expect(statistics.samples).to be_any - expect(statistics.failed).to be_zero - end -end