Skip to content

add env variables to the push adapter? #949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Cliffordwh opened this issue Mar 10, 2016 · 26 comments
Closed

add env variables to the push adapter? #949

Cliffordwh opened this issue Mar 10, 2016 · 26 comments
Labels
type:feature New feature or improvement of existing feature

Comments

@Cliffordwh
Copy link

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.

@flovilmart
Copy link
Contributor

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=""

@Cliffordwh
Copy link
Author

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

@flovilmart
Copy link
Contributor

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

@KudosGuy
Copy link

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...

@flovilmart
Copy link
Contributor

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

@KudosGuy
Copy link

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 }]"

@flovilmart
Copy link
Contributor

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

@KudosGuy
Copy link

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 }] }"
}
}]
}

@flovilmart
Copy link
Contributor

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 }] }"
}
}]
}

@KudosGuy
Copy link

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...

@flovilmart
Copy link
Contributor

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

@Cliffordwh
Copy link
Author

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

@KudosGuy
Copy link

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...

@Cliffordwh
Copy link
Author

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.

@KudosGuy
Copy link

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

@Cliffordwh
Copy link
Author

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"
                                             }
                             }

@KudosGuy
Copy link

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
                    }
    }

}

@Cliffordwh
Copy link
Author

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

@flovilmart
Copy link
Contributor

Guys, this is not how it should be configured

@flovilmart flovilmart reopened this Mar 14, 2016
@KudosGuy
Copy link

@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...

@flovilmart
Copy link
Contributor

Because the cli-definitions files is not supposed to be edited, as this file will be updated with npm when you update parse-server. There is either a bug when parsing/loading that environment variable, or, you're not providing a valid JSON or any other reason that make it fail. Locally, I can properly load the oneSignal adapter with that method.

@Cliffordwh
Copy link
Author

@flovilmart i agree. I've done so, but can you pass the options through?

@flovilmart
Copy link
Contributor

I just tested again and export PARSE_SERVER_PUSH='{"ios":{"pfx":"/home/parse/dev_cert.p12","bundleId":"someApp","production":false}}' is working correctly as expected.

For the one signal push adapter, the correct JSON would be:

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

At that point, I'm not sure if pm2 parses or dumps the JSON a strings,
but,
It seems that given that thread:

"PARSE_SERVER_PUSH": {"ios":{"pfx":"/home/parse/dev_cert.p12","bundleId":"someApp","production":false}}

should work as expected, if it doesn't, try with enclosing the JSON with single quotes

@Cliffordwh
Copy link
Author

@flovilmart Thanks, i see it doesn't use "options". Makes sense now.

@flovilmart
Copy link
Contributor

@Cliffordwh this is actually a bug in the adapter loader that don't pass the .options for the push as it's been originally structured differently than other adapter options.

Does it work with the basic options?

@KudosGuy
Copy link

fyi... you were right it didnt work becasue of the pm2, even though I reloaded and restarted the parse server via pm2 command it didnt load the new file config but some cached version so It never initialized the push so the PARSE_SERVER_PUSH works good, my mistake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or improvement of existing feature
Projects
None yet
Development

No branches or pull requests

4 participants