file_sv 0.1.13 → 0.2.0

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: c69a4a4dec09d95aa3ec0ef6aa3871c2f3d53b22a0ec265b8b270a2a940a8177
4
- data.tar.gz: 0bad44a25fe5e26efc4145290d939b2298912c9b185def00b92a8fc57db2acb9
3
+ metadata.gz: 7177e3a064f21ddcd10c0e939d9557460e23a260d247cfbed515a94a5b9265a3
4
+ data.tar.gz: e5cc7b549e0d6264a2a357a00de1d85ef18b7aafa757c621c0eeb647bc6db332
5
5
  SHA512:
6
- metadata.gz: 2fefabfaf7af9116e9ecdf160151dd081112aa591f28e5b231719732c079d4f6fbc4973afc964b4a8295611d19a3d798c085a5d50d173fbe188477fbf6dee8dc
7
- data.tar.gz: 177338aca5865d57008934cea16600890048effa3ce33ace8fd36437df0855250d89d977702c683c57d4dfb6a5904fed3769b6a6eaf131a1b3340ce333a4435d
6
+ metadata.gz: 61d515119cc7b4d3cefca1f8231c2d85f51394518e448013b4457271f01dddffd370426a5f4077bd5c05f7a446085643524c2968a443b0a1fd8fd86a5b3a6276
7
+ data.tar.gz: 96c064f198dbea63b6c5f251f4b2758856759f604cf8b3f3e31ccbb80fc895ee9d8861fe486e605d6a01feaab5f848a46d81501beadd1f1fee975d7bec9de146
@@ -130,6 +130,19 @@ class PlannedEndpoint
130
130
  ERB.new(File.read(serving_file_name)).result(binding)
131
131
  end
132
132
 
133
+ # Log when API is called
134
+ def log_call(params)
135
+ if params.keys.count > 0
136
+ show_params = []
137
+ params.each do |key, value|
138
+ show_params << "#{key}=#{value}"
139
+ end
140
+ "#{self.method} #{self.path}?#{show_params.join('&')}"
141
+ else
142
+ "#{self.method} #{self.path}"
143
+ end
144
+ end
145
+
133
146
  def short_description
134
147
  desc = self.status_code.to_s
135
148
  desc += " (delay #{self.delay} sec)" if self.delay > 0
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FileSv
4
- VERSION = "0.1.13"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -58,7 +58,7 @@ for more details'
58
58
  [endpoint.status_code, output_for(endpoint, binding)]
59
59
  end
60
60
 
61
- SvPlan.endpoints.each do |_endpoint_path, endpoint_value|
61
+ SvPlan.endpoints.each do |endpoint_path, endpoint_value|
62
62
  endpoint_value.each do |_method_name, endpoints|
63
63
  endpoint_base = endpoints[0]
64
64
  documentation "Endpoint #{endpoint_base.path}" do
@@ -66,19 +66,29 @@ for more details'
66
66
  end
67
67
  if endpoint_base.path.include? "#{File::Separator}:"
68
68
  send(endpoint_base.method, endpoint_base.path) do |id|
69
+ response["Access-Control-Allow-Origin"] = "*"
69
70
  endpoint = endpoints.sample
70
71
  @params = params
71
- puts "#{endpoint_base.method} #{endpoint_base.path} ?#{@params}"
72
+ puts endpoint.log_call(@params)
72
73
  serve endpoint, id
73
74
  end
74
75
  else
75
76
  send(endpoint_base.method, endpoint_base.path) do
77
+ response["Access-Control-Allow-Origin"] = "*"
76
78
  endpoint = endpoints.sample
77
79
  @params = params
78
- puts "#{endpoint_base.method} #{endpoint_base.path} ?#{@params}" unless ENV['ignore_path'] && ("/#{ENV['ignore_path']}" == endpoint_base.path)
80
+ puts endpoint.log_call(@params) unless ENV['ignore_path'] && ("/#{ENV['ignore_path']}" == endpoint_base.path)
79
81
  serve endpoint
80
82
  end
81
83
  end
82
84
  end
85
+ # options endpoint for CORS
86
+ options endpoint_path do
87
+ puts "options: #{endpoint_path}"
88
+ response["Allow"] = "*"
89
+ response["Access-Control-Allow-Origin"] = "*"
90
+ response["Access-Control-Allow-Methods"] = "*"
91
+ response["Access-Control-Allow-Headers"] = "*"
92
+ end
83
93
  end
84
94
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file_sv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Garratt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-26 00:00:00.000000000 Z
11
+ date: 2024-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faker