phaedra 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ac7eff901bd41a6da00ead154dc726635a7663597f5dd263fbe07c6f8df8821
4
- data.tar.gz: 3eaafe5f99657959f22bd097191329404469087fc864ea980ba85a15156c87ce
3
+ metadata.gz: 7f0e4c33ad4a5241f2a6b7455522db8389a1bc2323ef4542ad75546b2b874a08
4
+ data.tar.gz: 42f380fa9cb7a620da9591862c7fd7abbd4022e8046c1ed8f089e902a052c1c2
5
5
  SHA512:
6
- metadata.gz: 83c5681c356986221a82202728e3efdfe912f9db5c82bf66b388bb38a1e9450aac8269bda442fbca528230f64e8615446e7f8231cae9080fabd11c02fefee216
7
- data.tar.gz: 5631c0968e80834d7b571547151e1e9addcc64136e07e73c91828afcde277996763bf05b9591896ec530eefabbd2ede670f3fffbbdd902d26cadbcfe3a173138
6
+ metadata.gz: 0003a862d70c030695b33c1318c69c14eb3f0eda149590e485083827d6c703c06d68dbf8daa6c39e911274b5a5527c2e043aa327e18759bdb8ff970179e764cd
7
+ data.tar.gz: a5a22957adcb6c3e1fbce24e39e4c7b582381936b3d832d23ea32813888d5789ea779e89116fb3b16ac1a7122db97ac77d6de2fdd909ee791d351629f3c7dfcb
data/README.md CHANGED
@@ -89,13 +89,14 @@ require_relative "../lib/shared_code"
89
89
 
90
90
  class PhaedraFunction < Phaedra::Base
91
91
  def get(params)
92
- "Run it once! #{SharedCode.run_once}"
92
+ "Run it once! #{SharedCode.run_once} / #{Time.now}"
93
93
  end
94
94
  end
95
95
  ```
96
96
 
97
97
  ```ruby
98
98
  # lib/shared_code.rb
99
+
99
100
  module SharedCode
100
101
  def self.run_once
101
102
  @one_time ||= Time.now
@@ -103,7 +104,9 @@ module SharedCode
103
104
  end
104
105
  ```
105
106
 
106
- Now each time you invoke the function at `/api/run-it-once`, the timestamp will never change until the next redeployment.
107
+ Now each time you invoke the function at `/api/run-it-once`, the first timestamp will never change until the next redeployment.
108
+
109
+ **NOTE:** When running in a Rack-based configuration (see below), Ruby's `load` method is invoked for every request to any Phaedra function. This means Ruby has to parse and compile the code in your function each time. For small functions this happens extremely quickly, but if you find yourself writing a large function and seeing some performance slowdowns, consider extracting most of the function code to additional Ruby files and use the `require_relative` technique as mentioned above. The Ruby code in those required files will only be compiled once and all classes/modules/etc. will be saved in memory until the next redeployment.
107
110
 
108
111
  ## Deployment
109
112
 
@@ -212,7 +215,7 @@ require "phaedra"
212
215
  run Phaedra::RackApp.new
213
216
  ```
214
217
 
215
- Then run `rackup` in the terminal.
218
+ Then run `rackup` in the terminal, or use another Rack-compatible server like Puma or Passenger.
216
219
 
217
220
  The settings (and their defaults) you can pass to the `new` method are as follows:
218
221
 
@@ -223,6 +226,26 @@ The settings (and their defaults) you can pass to the `new` method are as follow
223
226
  }
224
227
  ```
225
228
 
229
+ Wondering if you can deploy a static site with an `api` folder via Nginx + Passenger? Yes, you can! Just configure your `my_site.conf` file like so:
230
+
231
+ ```nginxconf
232
+ server {
233
+ listen 80;
234
+ server_name www.domain.com;
235
+
236
+ # Tell Nginx and Passenger where your site destination folder is
237
+ root /home/me/my_site/output;
238
+
239
+ # Turn on Passenger
240
+ location /api {
241
+ passenger_enabled on;
242
+ passenger_ruby /usr/local/rvm/gems/ruby-2.6.6@mysite/wrappers/ruby;
243
+ }
244
+ }
245
+ ```
246
+
247
+ Change the `server_name`, `root`, and `passenger_ruby` paths to your particular setup and you'll be good to go. (If you run into any errors, double-check there's a `config.ru` in the parent folder of your site destination folder.)
248
+
226
249
  ### WEBrick
227
250
 
228
251
  Integrating Phaedra into a WEBrick server is pretty straightforward. Given a `server` object, it can be accomplished thusly:
@@ -2,7 +2,7 @@ require "phaedra"
2
2
 
3
3
  class PhaedraFunction < Phaedra::Base
4
4
  def get(params)
5
- response["Content-Type"] = "text/html"
5
+ response["Content-Type"] = "text/html; charset=utf-8"
6
6
  "<p>This is Interesting. 😁</p>"
7
7
  end
8
8
  end
@@ -122,7 +122,7 @@ module Phaedra
122
122
 
123
123
  def complete_response
124
124
  if @res.body.is_a?(String) && !@res["Content-Type"].start_with?("text/")
125
- @res["Content-Type"] = "text/plain"
125
+ @res["Content-Type"] = "text/plain; charset=utf-8"
126
126
  elsif @res["Content-Type"] == "application/json"
127
127
  @res.body = @res.body.to_json
128
128
  end
@@ -1,3 +1,3 @@
1
1
  module Phaedra
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phaedra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared White
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-08 00:00:00.000000000 Z
11
+ date: 2020-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  requirements: []
112
- rubygems_version: 3.0.8
112
+ rubygems_version: 3.0.6
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: Write serverless Ruby functions via a REST-like microframework compatible