From 098d6710048baa4ee54ad46af7fe307bbf4ab0ad Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Wed, 3 Feb 2016 17:00:10 -0500 Subject: [PATCH] Adds standalone parse server, configurable by environment, and that can start with npm start --- README.md | 36 ++++++++++++++++++++++++++++++++++++ bin/parse-server | 43 +++++++++++++++++++++++++++++++++++++++++++ package.json | 6 +++++- 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100755 bin/parse-server diff --git a/README.md b/README.md index 861fd89607..d7db7c9594 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,42 @@ app.listen(port, function() { ``` + +#### Standalone usage + +You can configure the Parse Server with environment variables: + +```js +PARSE_SERVER_DATABASE_URI +PARSE_SERVER_CLOUD_CODE_MAIN +PARSE_SERVER_COLLECTION_PREFIX +PARSE_SERVER_APPLICATION_ID // required +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 // required +PARSE_SERVER_FILE_KEY +PARSE_SERVER_FACEBOOK_APP_IDS // string of comma separated list + +``` + + + +Alernatively, you can use the `PARSE_SERVER_OPTIONS` environment variable set to the JSON of your configuration (see Usage). + +To start the server, just run `npm start`. + +##### Global installation + +You can install parse-server globally + +`$ npm install -g parse-server` + +Now you can just run `$ parse-server` from your command line. + + ### Supported * CRUD operations diff --git a/bin/parse-server b/bin/parse-server new file mode 100755 index 0000000000..57488af82d --- /dev/null +++ b/bin/parse-server @@ -0,0 +1,43 @@ +#!/usr/bin/env node +var express = require('express'); +var ParseServer = require("../index").ParseServer; + +var app = express(); + +var options = {}; +if (process.env.PARSE_SERVER_OPTIONS) { + + options = JSON.parse(process.env.PARSE_SERVER_OPTIONS); + +} else { + + options.databaseURI = process.env.PARSE_SERVER_DATABASE_URI; + options.cloud = process.env.PARSE_SERVER_CLOUD_CODE_MAIN; + options.collectionPrefix = process.env.PARSE_SERVER_COLLECTION_PREFIX; + + // Keys and App ID + options.appId = process.env.PARSE_SERVER_APPLICATION_ID; + options.clientKey = process.env.PARSE_SERVER_CLIENT_KEY; + options.restAPIKey = process.env.PARSE_SERVER_REST_API_KEY; + options.dotNetKey = process.env.PARSE_SERVER_DOTNET_KEY; + options.javascriptKey = process.env.PARSE_SERVER_JAVASCRIPT_KEY; + options.dotNetKey = process.env.PARSE_SERVER_DOTNET_KEY; + options.masterKey = process.env.PARSE_SERVER_MASTER_KEY; + options.fileKey = process.env.PARSE_SERVER_FILE_KEY; + // Comma separated list of facebook app ids + var facebookAppIds = process.env.PARSE_SERVER_FACEBOOK_APP_IDS; + + if (facebookAppIds) { + facebookAppIds = facebookAppIds.split(","); + options.facebookAppIds = facebookAppIds; + } +} + +var mountPath = process.env.PARSE_SERVER_MOUNT_PATH || "/"; +var api = new ParseServer(options); +app.use('/', api); + +var port = process.env.PORT || 1337; +app.listen(port, function() { + console.log('parse-server-example running on http://localhost:'+ port + mountPath); +}); \ No newline at end of file diff --git a/package.json b/package.json index 95003e813f..23e681b2bf 100644 --- a/package.json +++ b/package.json @@ -31,9 +31,13 @@ "scripts": { "pretest": "MONGODB_VERSION=${MONGODB_VERSION:=3.0.8} mongodb-runner start", "test": "TESTING=1 ./node_modules/.bin/istanbul cover --include-all-sources -x **/spec/** ./node_modules/.bin/jasmine", - "posttest": "mongodb-runner stop" + "posttest": "mongodb-runner stop", + "start": "./bin/parse-server" }, "engines": { "node": ">=4.1" + }, + "bin": { + "parse-server": "./bin/parse-server" } }