parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

add env variables to the push adapter?

Open Cliffordwh opened this issue 10 years ago • 26 comments

Hi Guys

Is is possible to add ENV variables to the push adapter? (Like we have just done for the S3 adapter in version 2.1.5)

or is this already available? PARSE_SERVER_PUSH?

Trying to set it in a json config with little success. Im not using the parse-server-example so i don't make use of a index.js initializer.

Making use of the oneSignalPushAdapter.

Cliffordwh avatar Mar 10 '16 10:03 Cliffordwh

you can configure with a PARSE_SERVER_PUSH or --push we expect the contents to be a string that can be parsed as a JSON.

in the JSON:

{ module: full/path/to/OSPushAdapter, options: { // one signal options } }

then JSON.stringify(pushOptions) PARSE_SERVER_PUSH=""

flovilmart avatar Mar 12 '16 02:03 flovilmart

@flovilmart Thanks , so if understand correctly in my ecosystem.json file I can set this full string in the PARSE_SERVER_PUSH="" ?

Cliffordwh avatar Mar 12 '16 03:03 Cliffordwh

That should work :) Let me know. BE careful with the path to the pushAdapter, this is tricky.

The adapterLoader is in Adapter, so it should work passing: '{"module": "./Push/OneSignalPushAdapter", "options": {}}'

./ being the relative path to the current file which is the adapterLoader

npm start -- --appId app --masterKey master --push '{"adapter": "./Push/OneSignalPushAdapter"}'

> [email protected] start /Users/florent/src/Parse/parse-server
> node ./bin/parse-server "--appId" "app" "--masterKey" "master" "--push" "{\"adapter\": \"./Push/OneSignalPushAdapter\"}"


/Users/florent/src/Parse/parse-server/lib/Adapters/Push/OneSignalPushAdapter.js:49
      throw "Trying to initialize OneSignalPushAdapter without oneSignalAppId or oneSignalApiKey";
      ^
Trying to initialize OneSignalPushAdapter without oneSignalAppId or oneSignalApiKey

flovilmart avatar Mar 12 '16 03:03 flovilmart

how do you write it in PUSH_SERVER_PUSH, I amalso not using index.js and I need to use this env var in my ecosystem but the parse is ignoring it so when I am trying to send Push it tells me It cannot find a sender...

KudosGuy avatar Mar 12 '16 18:03 KudosGuy

PARSE_SERVER_PUSH is an environment variable, just set it to the stringified JSON

flovilmart avatar Mar 12 '16 18:03 flovilmart

I did this and it doesnt work "PARSE_SERVER_PUSH": "'ios': [ { 'pfx': '/home/parse/dev_cert.p12', 'bundleId': 'SomeID', 'production': false },{ 'pfx': '/home/parse/production_cert.p12', 'bundleId': 'SomeID', 'production': true }]"

KudosGuy avatar Mar 12 '16 18:03 KudosGuy

The value you just set is not a valid JSON, PARSE_SERVER_PUSH='{"ios": [] }'

flovilmart avatar Mar 12 '16 18:03 flovilmart

it doesnt work too, parse is ignoring the PARSE_SERVER_PUSH { "apps" : [{ "name" : "parse-wrapper", "script" : "/usr/bin/parse-server", "watch" : true, "merge_logs" : true, "cwd" : "/home/parse", "env": { "PARSE_SERVER_CLOUD_CODE_MAIN": "/home/parse/cloud/main.js", "PARSE_SERVER_DATABASE_URI": "mongodb:...", "PARSE_SERVER_APPLICATION_ID": "id", "PARSE_SERVER_MASTER_KEY": "master", PARSE_SERVER_PUSH="{'ios': [ { 'pfx': '/home/parse/dev_cert.p12', 'bundleId': 'someID', 'production': false },{ 'pfx': '/home/parse/production_cert.p12', 'bundleId': 'someID', 'production': true }] }" } }] }

KudosGuy avatar Mar 12 '16 18:03 KudosGuy

Your configuration is malformed!

{
"apps" : [{
"name" : "parse-wrapper",
"script" : "/usr/bin/parse-server",
"watch" : true,
"merge_logs" : true,
"cwd" : "/home/parse",
"env": {
"PARSE_SERVER_CLOUD_CODE_MAIN": "/home/parse/cloud/main.js",
"PARSE_SERVER_DATABASE_URI": "mongodb:...",
"PARSE_SERVER_APPLICATION_ID": "id",
"PARSE_SERVER_MASTER_KEY": "master",
"PARSE_SERVER_PUSH": "{'ios': [ { 'pfx': '/home/parse/dev_cert.p12', 'bundleId': 'someID', 'production': false },{ 'pfx': '/home/parse/production_cert.p12', 'bundleId': 'someID', 'production': true }] }"
}
}]
}

flovilmart avatar Mar 12 '16 18:03 flovilmart

it doesnt work for me.... it keeps telling me in log that it cant find sender for push type..... I tried that on parse 2.1.4 and now on 2.1.6...

KudosGuy avatar Mar 12 '16 19:03 KudosGuy

Try to do it in a development environment, without pm2, I'm not familiar with pm2. but I can tell you that it works when properly setting environment variables. and running directly from command line

flovilmart avatar Mar 12 '16 19:03 flovilmart

@KudosGuy did you have any luck with this? Trying both OneSignal and the default with little success.

Cliffordwh avatar Mar 14 '16 07:03 Cliffordwh

no, I tried like 10 times to start the server with parse-server jsonconfig.json or npm start parse-server and many more and nothing worked, I would report it as a bug and maybe we can get more attention to this, but if you will install parse-server-example you will have the index.js and it is working there, but i really dont know why they are these two versions...

KudosGuy avatar Mar 14 '16 08:03 KudosGuy

I can confirm PARSE_SERVER_PUSH certainly does work. I got it to select the adapter ( OneSignal ) but struggling to pass the variables through. But i'm giving it a bash now.

Cliffordwh avatar Mar 14 '16 09:03 Cliffordwh

@Cliffordwh could you show me the syntax you used for PARSE_SERVER_PUSH?

KudosGuy avatar Mar 14 '16 09:03 KudosGuy

Options tho, doesn't seem to work for me. I'm getting Trying to initialize OneSignalPushAdapter without oneSignalAppId or oneSignalApiKey


   "PARSE_SERVER_PUSH" :  {"adapter" : "./Push/OneSignalPushAdapter",
                                 "options" : {
                                             "oneSignalAppId": "appid",
                                             "oneSignalApiKey": "apikey"
                                             }
                             }

Cliffordwh avatar Mar 14 '16 09:03 Cliffordwh

I got it running that I hardcoded it in /usr/lib/node_modules/parse-server/lib/cli/cli-definitions.js

"push": {
env: "PARSE_SERVER_PUSH",
help: "Configuration for push, as stringified JSON. See https://github.com/$",
default: {
            ios: {
                    pfx: "/home/parse/dev_cert.p12",
                    bundleId: "someApp",
                    production: false
                    }
    }

}

KudosGuy avatar Mar 14 '16 10:03 KudosGuy

Glad you got it working. I ended up coding in env's variables for the options too.

Cliffordwh avatar Mar 14 '16 10:03 Cliffordwh

Guys, this is not how it should be configured

flovilmart avatar Mar 14 '16 11:03 flovilmart

@flovilmart could you extend your response why? because for me it is the only solution for now... becasue when I add in my ecosystem.json PARSE_SERVER_PUSH it is never initialized, I can see that in log... but with my solution in cli-definitions.js it loads it on startup fine...

KudosGuy avatar Mar 14 '16 11:03 KudosGuy