-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
adds support for multiple apps on a single server #263
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,5 +32,11 @@ node_modules | |
# WebStorm/IntelliJ | ||
.idea | ||
|
||
# visual studio code | ||
.vscode | ||
|
||
# Babel.js | ||
lib/ | ||
|
||
# Cache | ||
.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
var path = require("path"); | ||
function loadFromCommandLine(args) { | ||
args = args || []; | ||
while (args.length > 0) { | ||
if (args[0] == "--config") { | ||
if (args.length < 2) { | ||
throw "Please specify the configuration file (json)"; | ||
} | ||
return require(path.resolve(args[1])); | ||
} | ||
args = args.slice(1, args.length); | ||
} | ||
} | ||
|
||
function loadFromEnvironment(env) { | ||
env = env || {}; | ||
var options = {}; | ||
if (env.PARSE_SERVER_OPTIONS) { | ||
|
||
options = JSON.parse(env.PARSE_SERVER_OPTIONS); | ||
|
||
} else { | ||
|
||
options.databaseURI = env.PARSE_SERVER_DATABASE_URI; | ||
options.cloud = env.PARSE_SERVER_CLOUD_CODE_MAIN; | ||
options.collectionPrefix = env.PARSE_SERVER_COLLECTION_PREFIX; | ||
|
||
// Keys and App ID | ||
options.appId = env.PARSE_SERVER_APPLICATION_ID; | ||
options.clientKey = env.PARSE_SERVER_CLIENT_KEY; | ||
options.restAPIKey = env.PARSE_SERVER_REST_API_KEY; | ||
options.dotNetKey = env.PARSE_SERVER_DOTNET_KEY; | ||
options.javascriptKey = env.PARSE_SERVER_JAVASCRIPT_KEY; | ||
options.dotNetKey = env.PARSE_SERVER_DOTNET_KEY; | ||
options.masterKey = env.PARSE_SERVER_MASTER_KEY; | ||
options.fileKey = env.PARSE_SERVER_FILE_KEY; | ||
// Comma separated list of facebook app ids | ||
var facebookAppIds = env.PARSE_SERVER_FACEBOOK_APP_IDS; | ||
|
||
if (facebookAppIds) { | ||
facebookAppIds = facebookAppIds.split(","); | ||
options.facebookAppIds = facebookAppIds; | ||
} | ||
var oauth = process.env.PARSE_SERVER_OAUTH_PROVIDERS; | ||
if (oauth) { | ||
options.oauth = JSON.parse(oauth); | ||
}; | ||
} | ||
return options; | ||
} | ||
|
||
|
||
module.exports = function() { | ||
var options = loadFromCommandLine(process.argv); | ||
if (typeof options == "undefined") { | ||
options = loadFromEnvironment(process.env); | ||
} | ||
return options; | ||
} | ||
|
||
module.exports.loadFromEnvironment = loadFromEnvironment; | ||
module.exports.loadFromCommandLine = loadFromCommandLine; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env node | ||
var rack = require('hat').rack(); | ||
|
||
var newApp = { | ||
"appId": rack(), | ||
"masterKey": rack(), | ||
"clientKey": rack(), | ||
"javascriptKey": rack(), | ||
"dotNetKey": rack(), | ||
"restAPIKey": rack(), | ||
"collectionPrefix": "", | ||
"databaseURI": "" | ||
}; | ||
|
||
process.stdout.write(JSON.stringify(newApp, null, 4)+"\n"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
var configuration = require("./support/parse-server-config.json"); | ||
var Parse = require("parse/node"); | ||
var apps = configuration.applications; | ||
var configLoader = require("../bin/config"); | ||
|
||
describe('Configuration loading', () => { | ||
|
||
it('should load a JSON from arguments', done => { | ||
var config = configLoader.loadFromCommandLine(["--config", "./spec/support/parse-server-config.json"]); | ||
expect(config).not.toBe(undefined); | ||
expect(config.applications.length).toBe(2); | ||
done(); | ||
}); | ||
|
||
it('should throw when json does not exist', done => { | ||
function load() { | ||
return configLoader.loadFromCommandLine(["--config", "./spec/support/bar.json"]); | ||
} | ||
expect(load).toThrow(); | ||
done(); | ||
}); | ||
|
||
it('should throw when json is missing', done => { | ||
function load() { | ||
return configLoader.loadFromCommandLine(["--config"]); | ||
} | ||
expect(load).toThrow("Please specify the configuration file (json)"); | ||
done(); | ||
}); | ||
|
||
it('should retun nothing when nothing is specified', done => { | ||
var config = configLoader.loadFromCommandLine(); | ||
expect(config).toBe(undefined); | ||
done(); | ||
}); | ||
|
||
it('should support more arguments', done => { | ||
var config = configLoader.loadFromCommandLine(["--some","--config", "./spec/support/parse-server-config.json", "--other"]); | ||
expect(config).not.toBe(undefined); | ||
expect(config.applications.length).toBe(2); | ||
done(); | ||
}); | ||
|
||
it('should load from environment', done => { | ||
var env = { | ||
PARSE_SERVER_DATABASE_URI: "", | ||
PARSE_SERVER_CLOUD_CODE_MAIN: "", | ||
PARSE_SERVER_COLLECTION_PREFIX: "", | ||
PARSE_SERVER_APPLICATION_ID: "", | ||
PARSE_SERVER_CLIENT_KEY: "", | ||
PARSE_SERVER_REST_API_KEY: "", | ||
PARSE_SERVER_DOTNET_KEY: "", | ||
PARSE_SERVER_JAVASCRIPT_KEY: "", | ||
PARSE_SERVER_DOTNET_KEY: "", | ||
PARSE_SERVER_MASTER_KEY: "", | ||
PARSE_SERVER_FILE_KEY: "", | ||
PARSE_SERVER_FACEBOOK_APP_IDS: "hello,world" | ||
} | ||
|
||
var config = configLoader.loadFromEnvironment(env); | ||
expect(config).not.toBe(undefined); | ||
expect(Object.keys(config).length).toBe(Object.keys(env).length); | ||
expect(config.facebookAppIds.length).toBe(2); | ||
expect(config.facebookAppIds).toContain("hello"); | ||
expect(config.facebookAppIds).toContain("world"); | ||
done(); | ||
}); | ||
|
||
it('should load from environment options', done => { | ||
var env = { | ||
PARSE_SERVER_OPTIONS: require("fs").readFileSync("./spec/support/parse-server-config.json") | ||
} | ||
|
||
var config = configLoader.loadFromEnvironment(env); | ||
expect(config).not.toBe(undefined); | ||
expect(config.applications.length).toBe(2); | ||
done(); | ||
}); | ||
|
||
it('should load empty configuration options', done => { | ||
var config = configLoader(); | ||
expect(config).not.toBe(undefined); | ||
expect(config).not.toBe({}); | ||
expect(config.appId).toBe(undefined); | ||
done(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -786,7 +786,11 @@ describe('Parse.ACL', () => { | |
equal(results.length, 1); | ||
var result = results[0]; | ||
ok(result); | ||
equal(result.id, object.id); | ||
if (!result) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prevents a crash when running the tests |
||
fail("should have result"); | ||
} else { | ||
equal(result.id, object.id); | ||
} | ||
done(); | ||
} | ||
}); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be app-specific, allowing multiple apps to share the same database... (that was the original intent of this variable.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we'll support multiple apps through ENV, seems painful to provide all APP ID settings. But I agree in principle with multiple levels of configuration for multiple apps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, and i see the part above for PARSE_SERVER_OPTIONS.