-
Notifications
You must be signed in to change notification settings - Fork 0
/
RestHandler.ol
55 lines (49 loc) · 1.9 KB
/
RestHandler.ol
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
include "console.iol"
include "json_utils.iol"
type incomingHeaderHandlerRequest:void{
.operation:string
.headers:undefined
}
type incomingHeaderHandlerResponse: undefined
type outgoingHeaderHandlerRequest:void{
.operation:string
.response?:undefined
}
type outgoingHeaderHandlerResponse: undefined
interface HeaderHandlerInterface{
RequestResponse:
incomingHeaderHandler(incomingHeaderHandlerRequest)(incomingHeaderHandlerResponse),
outgoingHeaderHandler(outgoingHeaderHandlerRequest)(outgoingHeaderHandlerResponse)
}
inputPort HeaderPort {
Protocol:sodep
Location:"local"
Interfaces:HeaderHandlerInterface
}
execution { concurrent }
main{
[incomingHeaderHandler(request)(response){
if ( request.operation == "api/login" ){
getJsonValue@JsonUtils(request.headers.("data"))(credentials)
response.username = credentials.username
response.password = credentials.password
} else if (request.operation == "api/register") {
getJsonValue@JsonUtils(request.headers.("data"))(credentials)
response.username = credentials.username
response.password = credentials.password
response.name = credentials.name
response.surname = credentials.surname
} else {//if (request.operation == "api/getMessages" || request.operation == "api/logout"){
response.sid = request.headers.cookies.session
} //\{(.*)\}
}]
[outgoingHeaderHandler(request)(response){
response.("Access-Control-Allow-Methods") = "POST,GET,DELETE,PUT,OPTIONS"
response.("Access-Control-Allow-Origin") = "*"
response.("Access-Control-Allow-Headers") = "Content-Type, Authorization"
//if(request.operation == "api/login"){
if(request.response.sid != ""){
response.("Set-Cookie") = "session="+request.response.sid
}
}]
}