macaw_framework 1.1.5 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +50 -29
- data/lib/macaw_framework/version.rb +1 -1
- data/lib/macaw_framework.rb +14 -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: d75c6de0b02d30691fa5f96e00b0b3ee57252ea1aa85a46d39233bcea0559116
|
4
|
+
data.tar.gz: ead04287539187c0eb4077c49f00ba1e197861ee60f915a9686d904630444ed3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c620f8210e450f2e830fa5089feb5843f04750f9399f32d31dae271c490676628648ba306d6d9084c4ee3272eb8bb85efe43f55a1d9f4db761731b82ba10d7e
|
7
|
+
data.tar.gz: 5c447df10c725b61407b9d1846975550894d9555d4e42b5e0154c6af70aa73fe1300995c90e71e5bb116581f94323f7a2e3dbb3b9b6603d4c604893621f9bea9
|
data/CHANGELOG.md
CHANGED
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,26 @@ 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` proporty 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
|
+
|
175
188
|
### Cron Jobs
|
176
189
|
|
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
|
190
|
+
Macaw Framework supports the declaration of cron jobs right in your application code. This feature allows developers to
|
191
|
+
define tasks that run at set intervals, starting after an optional delay. Each job runs in a separate thread, meaning
|
179
192
|
your cron jobs can execute in parallel without blocking the rest of your application.
|
180
193
|
|
181
194
|
Here's an example of how to declare a cron job:
|
@@ -191,7 +204,7 @@ Values for interval and start_delay are in seconds.
|
|
191
204
|
**Caution: Defining a lot of jobs with low interval can severely degrade performance.**
|
192
205
|
|
193
206
|
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!`.
|
207
|
+
MacawFramework without running a web server with the `start_without_server!` method, instead of `start!`.
|
195
208
|
|
196
209
|
### Tips
|
197
210
|
|
@@ -201,13 +214,13 @@ MacawFramework without running a web server with `start_without_server!` method,
|
|
201
214
|
MacawFramework::Macaw.new(custom_log: nil)
|
202
215
|
```
|
203
216
|
|
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.
|
217
|
+
- Cache invalidation time should be specified in seconds. In order to enable caching, The `application.json` file
|
218
|
+
should exist in the app main directory and it needs the `cache_invalidation` config set. It is possible to
|
219
|
+
provide a list of strings in the property `ignore_headers`. All the client headers with the same name as any
|
220
|
+
of the strings provided will be ignored from the caching strategy. This is useful to exclude headers like
|
221
|
+
correlation IDs from the caching strategy.
|
209
222
|
|
210
|
-
- URL parameters like `...endOfUrl?key1=value1&key2=value2` can be
|
223
|
+
- URL parameters like `...endOfUrl?key1=value1&key2=value2` can be found in the `context[:params]`
|
211
224
|
|
212
225
|
```ruby
|
213
226
|
m.get('/test_params') do |context|
|
@@ -218,23 +231,31 @@ end
|
|
218
231
|
- The default number of virtual threads in the thread pool is 200.
|
219
232
|
|
220
233
|
- 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`.
|
234
|
+
exists inside `application.json`.
|
222
235
|
|
223
236
|
- 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.
|
237
|
+
will be wrapped with HTTPS security using the provided certificate.
|
238
|
+
|
239
|
+
- The supported values for `min` and `max` in the SSL configuration are: `SSL2`, `SSL3`, `TLS1.1`, `TLS1.2`, and `TLS1.3`,
|
240
|
+
and the supported values for `key_type` are `RSA` and `EC`.
|
241
|
+
|
242
|
+
- If Prometheus is enabled, a GET endpoint will be defined at path `/metrics` to collect Prometheus metrics. This path
|
243
|
+
is configurable via the `application.json` file.
|
225
244
|
|
226
|
-
- The
|
227
|
-
and the
|
245
|
+
- The verb methods must always return a string or nil (used as the response), a number corresponding to the HTTP status
|
246
|
+
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
|
247
|
+
returns nil for body, status code, and headers, a default 200 OK status will be sent as the response.
|
228
248
|
|
229
|
-
-
|
230
|
-
|
249
|
+
- 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
|
250
|
+
for it.
|
231
251
|
|
232
|
-
-
|
233
|
-
|
234
|
-
|
252
|
+
- Ensure the "public" folder is placed in the same directory as the main.rb file: The "public" folder should contain any static assets,
|
253
|
+
such as CSS, JavaScript, or images, that your web application requires. Placing it in the same directory as the main.rb file ensures
|
254
|
+
that the server can correctly serve these assets.
|
235
255
|
|
236
|
-
-
|
237
|
-
|
256
|
+
- 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,
|
257
|
+
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
|
258
|
+
the necessary files and resources without any problems.
|
238
259
|
|
239
260
|
## Contributing
|
240
261
|
|
@@ -246,4 +267,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
246
267
|
|
247
268
|
## Code of Conduct
|
248
269
|
|
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).
|
270
|
+
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: __dir__)
|
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,17 @@ module MacawFramework
|
|
200
201
|
})
|
201
202
|
@routes << "#{prefix}.#{path_clean}"
|
202
203
|
end
|
204
|
+
|
205
|
+
def get_files_public_folder(dir)
|
206
|
+
folder_path = Pathname.new(File.expand_path("public", dir))
|
207
|
+
file_paths = folder_path.glob("**/*").select(&:file?)
|
208
|
+
file_paths.map { |path| "public/#{path.relative_path_from(folder_path)}" }
|
209
|
+
end
|
210
|
+
|
211
|
+
def create_endpoint_public_files(dir)
|
212
|
+
get_files_public_folder(dir).each do |file|
|
213
|
+
get(file) { |_context| return File.read(file).to_s, 200, {} }
|
214
|
+
end
|
215
|
+
end
|
203
216
|
end
|
204
217
|
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.6
|
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-07-
|
11
|
+
date: 2023-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prometheus-client
|