-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.rb
55 lines (37 loc) · 1.02 KB
/
start.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'sinatra'
require 'json'
require_relative 'server/encrypt'
require_relative 'server/decrypt'
before do
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'POST, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Content-Type'
end
get '/' do
'Server active!'
end
options '/encrypt' do
status 204
end
post '/encrypt' do
status 200
content_type :json
request_payload = JSON.parse(request.body.read)
input_string = request_payload['input']
input_key = request_payload['key']
encrypted_text = caeser_cypher_encrypt(input_string, input_key)
{ output:encrypted_text }.to_json
end
options '/decrypt' do
status 204
end
post '/decrypt' do
status 200
content_type :json
request_payload = JSON.parse(request.body.read)
input_string = request_payload['input']
input_key = request_payload['key']
decrypted_text = caeser_cypher_decrypt(input_string, input_key)
{ output: decrypted_text }.to_json
end
configure { set :server, :puma }