UnifiedPush / common-proxies

Mirror of https://codeberg.org/UnifiedPush/common-proxies
MIT License
24 stars 11 forks source link

FCM Distributors rewrite proxy #33

Closed p1gp1g closed 2 years ago

p1gp1g commented 2 years ago

ATM it is done with the following nginx + lua rule :

server {
   listen 127.0.0.1:1234;
   location / {
       access_by_lua_block{
           local json=require("cjson")
           ngx.req.read_body()
           local args = ngx.req.get_uri_args()
           local token = args["token"]
           local app = args["app"]
           local req = ngx.req.get_body_data()
           local newreq =  { ["to"] = token, ["data"] = { ["body"] = req, ["app"] = app } }
           local body = json.encode(newreq)
           ngx.req.set_body_data(body)
       }

       proxy_set_header         Authorization key=AAAAB<redaced> ;
       proxy_set_header         Content-Type application/json;
       proxy_pass                       https://fcm.googleapis.com/fcm/send;
       proxy_set_header            Host fcm.googleapis.com;

       # Force https
       #if ($scheme = http) {
       #    rewrite ^ https://$server_name$request_uri? permanent;
       # }
   }
 }

We need to make a /v2 endpoint that base64 encodes the request to follow AND_2.0.0 and keeping this one for the old one. It will be easier to do it with common-proxies

p1gp1g commented 2 years ago

The base64 rule on a new endpoint is also required for the v2 embedded_distrib + keeping the old one too

karmanyaahm commented 2 years ago

I'll try do it today

karmanyaahm commented 2 years ago

1

Are there any differences between FCM Distributor (FCMD) proxy and Embedded FCM Distributor (EFCMD) proxy apart from the parameters: FCMD: 'body' 'app' EFCMD: 'body' 'instance'

If there isn't any difference other than naming, can v2 make both 'body' & 'instance' so both FCMD and EFCMD can use the same code?

2

In the FCM JSON payload (i.e. the intents received on android), would it be fine if 'body' 'app' 'instance' are replaced by 'b' 'a' 'i'.

This is because base64 encoding will already have a lot of overhead, this might be a tiny (7-12 byte) improvement.

karmanyaahm commented 2 years ago

3rd proposal

making 'v2' a query param rather than a /v2 path will simplify the code. is that fine?

p1gp1g commented 2 years ago

Are there any differences between FCM Distributor (FCMD) proxy and Embedded FCM Distributor (EFCMD) proxy apart from the parameters: FCMD: 'body' 'app' EFCMD: 'body' 'instance'

No

If there isn't any difference other than naming, can v2 make both 'body' & 'instance' so both FCMD and EFCMD can use the same code?

Yes, that's possible *

That would probably help to use the EFCMD inside FCMD actually

In the FCM JSON payload (i.e. the intents received on android), would it be fine if 'body' 'app' 'instance' are replaced by 'b' 'a' 'i'.

This is because base64 encoding will already have a lot of overhead, this might be a tiny (7-12 byte) improvement.

That's also possible *

making 'v2' a query param rather than a /v2 path will simplify the code. is that fine?

OK too

* We just need to be careful to use old param for the old versions

karmanyaahm commented 2 years ago

Ok, I'll make the endpoint support 3 modes:

v1 FCMD: url: 'token' 'app' - payload: 'body' 'app' v1 EFCMD: url: 'token' 'instance' - payload: 'body' 'instance' v2: url: 'token' 'instance' 'v2' - payload: 'b' 'i'

The 3 modes will be differentiated between based on the url query params

karmanyaahm commented 2 years ago

https://github.com/UnifiedPush/common-proxies/blob/5f538e0df75f9ed9767543b4ca73344bb448c6dc/main_test.go#L54-L56

is how they can be used on the client side