macaw_framework 1.1.5 → 1.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +52 -29
- data/lib/macaw_framework/version.rb +1 -1
- data/lib/macaw_framework.rb +18 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 491bca651168a6934d2271ea54b4d123d986b2cf467d47f8da6ec512988d71e5
|
4
|
+
data.tar.gz: 16607cefef4714fcf6062d540b5dba60985e6276f4569ad20fe65f1eef199ff3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b93f8683ec3b67450ed8321000822db8fc8b049eace487711df574d8f1e20943aaf5f5366640be0a01ef461919e66a4510ab876b4f408f3c42fc92efb1d12a41
|
7
|
+
data.tar.gz: '02087194f65d038a66c4e4618c4142c2bdc569111c278ad14a19dc658daa4f25e2017f3b5d4349fdcdc41f762234dc1a3835593df137c8c35452c0780f0665a8'
|
data/CHANGELOG.md
CHANGED
@@ -96,3 +96,11 @@
|
|
96
96
|
|
97
97
|
- Improving number of virtual threads to 200.
|
98
98
|
- Fixing misleading description on ThreadServer.
|
99
|
+
|
100
|
+
## [1.1.6] - 2023-07-19
|
101
|
+
|
102
|
+
- Creating support for public folder
|
103
|
+
|
104
|
+
## [1.1.7] - 2023-08-12
|
105
|
+
|
106
|
+
- Fixing a bug where the server would not start with the public folder feature enabled on non-Unix systems
|
data/README.md
CHANGED
@@ -16,6 +16,7 @@ provides developers with the essential tools to quickly build and deploy their a
|
|
16
16
|
+ [Session management: Handle user sessions securely with server-side in-memory storage](#session-management-handle-user-sessions-securely-with-server-side-in-memory-storage)
|
17
17
|
+ [Configuration: Customize various aspects of the framework through the application.json configuration file, such as rate limiting, SSL support, and Prometheus integration](#configuration-customize-various-aspects-of-the-framework-through-the-applicationjson-configuration-file-such-as-rate-limiting-ssl-support-and-prometheus-integration)
|
18
18
|
+ [Monitoring: Easily monitor your application performance and metrics with built-in Prometheus support](#monitoring-easily-monitor-your-application-performance-and-metrics-with-built-in-prometheus-support)
|
19
|
+
+ [Routing for "public" Folder: Serve Static Assets](#routing-for-public-folder-serve-static-assets)
|
19
20
|
+ [Cron Jobs](#cron-jobs)
|
20
21
|
+ [Tips](#tips)
|
21
22
|
* [Contributing](#contributing)
|
@@ -33,7 +34,7 @@ provides developers with the essential tools to quickly build and deploy their a
|
|
33
34
|
|
34
35
|
## Installation
|
35
36
|
|
36
|
-
Install the gem and add to the application's Gemfile by executing:
|
37
|
+
Install the gem and add it to the application's Gemfile by executing:
|
37
38
|
|
38
39
|
$ bundle add macaw_framework
|
39
40
|
|
@@ -51,8 +52,6 @@ MacawFramework is built to be highly compatible, since it uses only native Ruby
|
|
51
52
|
|
52
53
|
- **JRuby**: MacawFramework is also compatible with JRuby, a version of Ruby that runs on the Java Virtual Machine (JVM).
|
53
54
|
|
54
|
-
Sure, here's a rewritten section for your README:
|
55
|
-
|
56
55
|
## MacawFramework's Built-In Web Server
|
57
56
|
|
58
57
|
MacawFramework includes a built-in web server based on Ruby's TCPServer class, providing a lightweight yet robust solution for serving your web applications. It incorporates features such as SSL security and a thread-based architecture, offering a balance of simplicity, performance, and robustness.
|
@@ -88,26 +87,24 @@ end
|
|
88
87
|
|
89
88
|
m.post('/submit_data/:path_variable') do |context|
|
90
89
|
context[:body] # Client body data
|
91
|
-
context[:params] # Client params, like
|
90
|
+
context[:params] # Client params, like URL parameters or variables
|
92
91
|
context[:headers] # Client headers
|
93
92
|
context[:params][:path_variable] # The defined path variable can be found in :params
|
94
93
|
context[:client] # Client session
|
95
94
|
end
|
96
95
|
|
97
96
|
m.start!
|
98
|
-
|
99
97
|
```
|
100
98
|
|
101
99
|
### Caching: Improve performance by caching responses and configuring cache invalidation
|
102
100
|
|
103
101
|
```ruby
|
104
102
|
m.get('/cached_data', cache: true) do |context|
|
105
|
-
# Retrieve data
|
103
|
+
# Retrieve data
|
106
104
|
end
|
107
105
|
```
|
108
106
|
|
109
|
-
Observation: To activate caching you also have to set
|
110
|
-
See section below for configurations.
|
107
|
+
*Observation: To activate caching, you also have to set its properties in the `application.json` file. If you don't, the caching strategy will not work. See the Configuration section below for more details.*
|
111
108
|
|
112
109
|
### Session management: Handle user sessions securely with server-side in-memory storage
|
113
110
|
|
@@ -172,10 +169,28 @@ end
|
|
172
169
|
curl http://localhost:8080/metrics
|
173
170
|
```
|
174
171
|
|
172
|
+
### Routing for "public" Folder: Serve Static Assets
|
173
|
+
|
174
|
+
MacawFramework allows you to serve static assets, such as CSS, JavaScript, images, etc., through the "public" folder.
|
175
|
+
To enable this functionality, make sure the "public" folder is placed in the same directory as the main.rb file.
|
176
|
+
The "public" folder should contain any static assets required by your web application.
|
177
|
+
|
178
|
+
To avoid issues, instantiate the Macaw using the `dir` property as following:
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
MacawFramework::Macaw.new(dir: __dir__)
|
182
|
+
```
|
183
|
+
|
184
|
+
By default, MacawFramework will automatically serve files from the "public" folder recursively when matching requests
|
185
|
+
are made. For example, if you have an image file named "logo.png" inside a "img" folder in the "public" folder, it will
|
186
|
+
be accessible at http://yourdomain.com/img/logo.png without any additional configuration.
|
187
|
+
|
188
|
+
#### Caution: This is incompatible with most non-unix systems, such as Windows. If you are using a non-unix system, you will need to manually configure the "public" folder and use dir as nil to avoid problems.
|
189
|
+
|
175
190
|
### Cron Jobs
|
176
191
|
|
177
|
-
Macaw Framework supports the declaration of cron jobs right in your application code. This feature allows developers to
|
178
|
-
define tasks that run at set intervals, starting after an optional delay. Each job runs in a separate thread, meaning
|
192
|
+
Macaw Framework supports the declaration of cron jobs right in your application code. This feature allows developers to
|
193
|
+
define tasks that run at set intervals, starting after an optional delay. Each job runs in a separate thread, meaning
|
179
194
|
your cron jobs can execute in parallel without blocking the rest of your application.
|
180
195
|
|
181
196
|
Here's an example of how to declare a cron job:
|
@@ -191,7 +206,7 @@ Values for interval and start_delay are in seconds.
|
|
191
206
|
**Caution: Defining a lot of jobs with low interval can severely degrade performance.**
|
192
207
|
|
193
208
|
If you want to build an application with just cron jobs, that don't need to run a web server, you can start
|
194
|
-
MacawFramework without running a web server with `start_without_server!` method, instead of `start!`.
|
209
|
+
MacawFramework without running a web server with the `start_without_server!` method, instead of `start!`.
|
195
210
|
|
196
211
|
### Tips
|
197
212
|
|
@@ -201,13 +216,13 @@ MacawFramework without running a web server with `start_without_server!` method,
|
|
201
216
|
MacawFramework::Macaw.new(custom_log: nil)
|
202
217
|
```
|
203
218
|
|
204
|
-
- Cache invalidation time should be specified in seconds. In order to enable caching, The application.json file
|
205
|
-
should exist in the app main directory and it
|
206
|
-
provide a list of strings in the property `ignore_headers`. All the client headers with the same name
|
207
|
-
of the strings provided will be ignored from caching strategy. This is useful to exclude headers like
|
208
|
-
correlation IDs from the caching strategy.
|
219
|
+
- Cache invalidation time should be specified in seconds. In order to enable caching, The `application.json` file
|
220
|
+
should exist in the app main directory and it needs the `cache_invalidation` config set. It is possible to
|
221
|
+
provide a list of strings in the property `ignore_headers`. All the client headers with the same name as any
|
222
|
+
of the strings provided will be ignored from the caching strategy. This is useful to exclude headers like
|
223
|
+
correlation IDs from the caching strategy.
|
209
224
|
|
210
|
-
- URL parameters like `...endOfUrl?key1=value1&key2=value2` can be
|
225
|
+
- URL parameters like `...endOfUrl?key1=value1&key2=value2` can be found in the `context[:params]`
|
211
226
|
|
212
227
|
```ruby
|
213
228
|
m.get('/test_params') do |context|
|
@@ -218,23 +233,31 @@ end
|
|
218
233
|
- The default number of virtual threads in the thread pool is 200.
|
219
234
|
|
220
235
|
- Rate Limit window should also be specified in seconds. Rate limit will be activated only if the `rate_limiting` config
|
221
|
-
exists inside `application.json`.
|
236
|
+
exists inside `application.json`.
|
222
237
|
|
223
238
|
- If the SSL configuration is provided in the `application.json` file with valid certificate and key files, the TCP server
|
224
|
-
will be wrapped with HTTPS security using the provided certificate.
|
239
|
+
will be wrapped with HTTPS security using the provided certificate.
|
240
|
+
|
241
|
+
- The supported values for `min` and `max` in the SSL configuration are: `SSL2`, `SSL3`, `TLS1.1`, `TLS1.2`, and `TLS1.3`,
|
242
|
+
and the supported values for `key_type` are `RSA` and `EC`.
|
243
|
+
|
244
|
+
- If Prometheus is enabled, a GET endpoint will be defined at path `/metrics` to collect Prometheus metrics. This path
|
245
|
+
is configurable via the `application.json` file.
|
225
246
|
|
226
|
-
- The
|
227
|
-
and the
|
247
|
+
- The verb methods must always return a string or nil (used as the response), a number corresponding to the HTTP status
|
248
|
+
code to be returned to the client, and the response headers as a Hash or nil. If an endpoint doesn't return a value or
|
249
|
+
returns nil for body, status code, and headers, a default 200 OK status will be sent as the response.
|
228
250
|
|
229
|
-
-
|
230
|
-
|
251
|
+
- For cron jobs without a start_delay, a value of 0 will be used. For a job without a name, a unique name will be generated
|
252
|
+
for it.
|
231
253
|
|
232
|
-
-
|
233
|
-
|
234
|
-
|
254
|
+
- Ensure the "public" folder is placed in the same directory as the main.rb file: The "public" folder should contain any static assets,
|
255
|
+
such as CSS, JavaScript, or images, that your web application requires. Placing it in the same directory as the main.rb file ensures
|
256
|
+
that the server can correctly serve these assets.
|
235
257
|
|
236
|
-
-
|
237
|
-
|
258
|
+
- Always run the main.rb file from a terminal in the same directory: To avoid any potential issues related to file paths and relative paths,
|
259
|
+
make sure to run the main.rb file from a terminal in the same directory where it is located. This will ensure that the application can access
|
260
|
+
the necessary files and resources without any problems.
|
238
261
|
|
239
262
|
## Contributing
|
240
263
|
|
@@ -246,4 +269,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
246
269
|
|
247
270
|
## Code of Conduct
|
248
271
|
|
249
|
-
Everyone interacting in the MacawFramework project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ariasdiniz/macaw_framework/blob/main/CODE_OF_CONDUCT.md).
|
272
|
+
Everyone interacting in the MacawFramework project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](https://github.com/ariasdiniz/macaw_framework/blob/main/CODE_OF_CONDUCT.md).
|
data/lib/macaw_framework.rb
CHANGED
@@ -24,7 +24,7 @@ module MacawFramework
|
|
24
24
|
|
25
25
|
##
|
26
26
|
# @param {Logger} custom_log
|
27
|
-
def initialize(custom_log: Logger.new($stdout), server: ThreadServer)
|
27
|
+
def initialize(custom_log: Logger.new($stdout), server: ThreadServer, dir: nil)
|
28
28
|
begin
|
29
29
|
@routes = []
|
30
30
|
@macaw_log ||= custom_log
|
@@ -41,6 +41,7 @@ module MacawFramework
|
|
41
41
|
rescue StandardError => e
|
42
42
|
@macaw_log&.warn(e.message)
|
43
43
|
end
|
44
|
+
create_endpoint_public_files(dir)
|
44
45
|
@port ||= 8080
|
45
46
|
@bind ||= "localhost"
|
46
47
|
@config ||= nil
|
@@ -200,5 +201,21 @@ module MacawFramework
|
|
200
201
|
})
|
201
202
|
@routes << "#{prefix}.#{path_clean}"
|
202
203
|
end
|
204
|
+
|
205
|
+
def get_files_public_folder(dir)
|
206
|
+
if dir.nil?
|
207
|
+
[]
|
208
|
+
else
|
209
|
+
folder_path = Pathname.new(File.expand_path("public", dir))
|
210
|
+
file_paths = folder_path.glob("**/*").select(&:file?)
|
211
|
+
file_paths.map { |path| "public/#{path.relative_path_from(folder_path)}" }
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def create_endpoint_public_files(dir)
|
216
|
+
get_files_public_folder(dir).each do |file|
|
217
|
+
get(file) { |_context| return File.read(file).to_s, 200, {} }
|
218
|
+
end
|
219
|
+
end
|
203
220
|
end
|
204
221
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: macaw_framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aria Diniz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prometheus-client
|