|
2 | 2 |
|
3 | 3 | var batch = require('./batch'), |
4 | 4 | bodyParser = require('body-parser'), |
5 | | - CacheProvider = require('./classes/CacheProvider'), |
6 | | - DatabaseAdapter = require('./DatabaseAdapter'), |
7 | 5 | express = require('express'), |
8 | | - FilesAdapter = require('./FilesAdapter'), |
9 | 6 | S3Adapter = require('./S3Adapter'), |
10 | 7 | middlewares = require('./middlewares'), |
11 | 8 | multer = require('multer'), |
12 | 9 | Parse = require('parse/node').Parse, |
13 | 10 | PromiseRouter = require('./PromiseRouter'), |
14 | 11 | httpRequest = require('./httpRequest'); |
15 | 12 |
|
| 13 | +var ParseApp = require('./classes/ParseApp'); |
| 14 | +var CacheProvider = require('./classes/CacheProvider'); |
| 15 | +var FilesProvider = require('./classes/FilesProvider'); |
| 16 | +var DatabaseProvider = require('./classes/DatabaseProvider'); |
| 17 | + |
16 | 18 | // Mutate the Parse object to add the Cloud Code handlers |
17 | 19 | addParseCloud(); |
18 | 20 |
|
@@ -40,53 +42,31 @@ addParseCloud(); |
40 | 42 | // "javascriptKey": optional key from Parse dashboard |
41 | 43 |
|
42 | 44 | function ParseServer(args) { |
43 | | - if (!args.appId || !args.masterKey) { |
44 | | - throw 'You must provide an appId and masterKey!'; |
45 | | - } |
46 | | - |
47 | 45 | // Setup providers |
48 | 46 | CacheProvider.setup(args.cache); |
| 47 | + FilesProvider.setup(args.files); |
| 48 | + DatabaseProvider.setup(args.database); |
| 49 | + |
| 50 | + // Instantiate the app |
| 51 | + var app = new ParseApp(args.app); |
49 | 52 |
|
50 | | - if (args.databaseAdapter) { |
51 | | - DatabaseAdapter.setAdapter(args.databaseAdapter); |
52 | | - } |
53 | | - if (args.filesAdapter) { |
54 | | - FilesAdapter.setAdapter(args.filesAdapter); |
55 | | - } |
56 | | - if (args.databaseURI) { |
57 | | - DatabaseAdapter.setAppDatabaseURI(args.appId, args.databaseURI); |
58 | | - } |
59 | 53 | if (args.cloud) { |
| 54 | + // Add the Parse.Cloud global function definitions |
60 | 55 | addParseCloud(); |
61 | | - if (typeof args.cloud === 'function') { |
62 | | - args.cloud(Parse) |
63 | | - } else if (typeof args.cloud === 'string') { |
64 | | - require(args.cloud); |
| 56 | + |
| 57 | + // Load the cloud code entry point |
| 58 | + if (typeof args.cloud.entry === 'function') { |
| 59 | + args.cloud.entry(Parse) |
| 60 | + } else if (typeof args.cloud.entry === 'string') { |
| 61 | + require(args.cloud.entry); |
65 | 62 | } else { |
66 | 63 | throw new Error("argument 'cloud' must either be a string or a function"); |
67 | 64 | } |
68 | | - |
69 | | - } |
70 | | - |
71 | | - var appInfo = { |
72 | | - masterKey: args.masterKey, |
73 | | - collectionPrefix: args.collectionPrefix || '', |
74 | | - clientKey: args.clientKey || '', |
75 | | - javascriptKey: args.javascriptKey || '', |
76 | | - dotNetKey: args.dotNetKey || '', |
77 | | - restAPIKey: args.restAPIKey || '', |
78 | | - fileKey: args.fileKey || 'invalid-file-key', |
79 | | - facebookAppIds: args.facebookAppIds || [] |
80 | | - }; |
81 | | - |
82 | | - // To maintain compatibility. TODO: Remove in v2.1 |
83 | | - if (process.env.FACEBOOK_APP_ID) { |
84 | | - appInfo['facebookAppIds'].push(process.env.FACEBOOK_APP_ID); |
85 | 65 | } |
86 | 66 |
|
87 | 67 | // Cache the application information indefinitely |
88 | 68 | var cache = CacheProvider.getAdapter(); |
89 | | - cache.put(args.appId, appInfo, Infinity); |
| 69 | + cache.put(app.appId, app, Infinity); |
90 | 70 |
|
91 | 71 | // Initialize the node client SDK automatically |
92 | 72 | Parse.initialize(args.appId, args.javascriptKey || '', args.masterKey); |
|
0 commit comments