Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Example express application adding the parse-server module to expose Parse
// compatible API routes.
'use strict';
const express = require('express');
const ParseServer = require('parse-server').ParseServer;
const config = require('../config.js');
const port = 1337;
const attr = {
databaseURI: process.env.DB_URI || 'mongodb://localhost:27017/dev',
appId: config.applicationId,
masterKey: 'myMasterKey', //Add your master key here. Keep it secret!
serverURL: 'http://localhost:' + port + config.mountPath,
};
console.log(attr);
var api = new ParseServer(attr);
var app = express();
app.use(config.mountPath, api);
app.post('/shutdown', function (req, res) {
res.send('bye~\n');
process.exit(0);
});
var httpServer = require('http').createServer(app);
httpServer.listen(port, function () {
console.log('running on port ' + port + '.');
console.log('mount path', config.mountPath, '.');
});
const createServer = async () => {
const app = express();
const port = 8000;
const mongoServerInstance = new MongoInMemory(port); // DEFAULT PORT is 27017
await mongoServerInstance.start();
const mongouri = mongoServerInstance.getMongouri('myDatabaseName');
const api = new ParseServer({
databaseURI: mongouri,
appId: 'myAppId',
masterKey: 'myMasterKey',
javascriptKey: 'javascriptKey',
fileKey: 'optionalFileKey',
restAPIKey: 'java',
serverURL: 'http://localhost:1337/parse',
});
app.use('/parse', api);
app.get('/find', async (req, res) => {
try {
const testObjects = await TestObject._find(TestObject._query());
if (testObjects) {
res.status(200).send();
var ParseDashboard = require('parse-dashboard');
// express
var app = express();
// Serve static assets from the /public folder
app.use('/public', express.static(path.join(__dirname, '/public')));
// create api server
var PARSE_APP = PARSE_CONFIG.apps[0];
if (!PARSE_APP.databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}
// parse server
var api = new ParseServer({
databaseURI: PARSE_APP.databaseUri || 'mongodb://localhost:27017/dev',
cloud: PARSE_APP.cloudCodeMain || __dirname + '/cloud/main.js',
appId: PARSE_APP.appId || 'myAppId',
masterKey: PARSE_APP.masterKey || '', //Add your master key here. Keep it secret!
fileKey: PARSE_APP.fileKey || '', // Add the file key to provide access to files already hosted on Parse
serverURL: PARSE_APP.localServerURL || PARSE_APP.serverURL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
// liveQuery: {
// classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
// },
// push: {
// android: { senderId: process.env.GCM_SENDER_ID, apiKey: process.env.GCM_API_KEY },
// ios: [
// { pfx: __dirname + "/push/aps_development.p12", bundleId: process.env.APP_BUNDLE_ID, production: false },
// { pfx: __dirname + "/push/aps_production.p12", bundleId: process.env.APP_BUNDLE_ID, production: true }
// ]
// },
const app = express();
const {
APP_ID,
MASTER_KEY,
GCM_SENDER_ID,
GCM_API_KEY,
PFX_PATH_DEV,
PFX_PASS_DEV,
PFX_PATH_PROD,
PFX_PASS_PROD,
APP_BUNDLE_ID,
IS_PRODUCTION
} = process.env;
const api = new ParseServer({
databaseURI: 'mongodb://mongo-parse-server/', // Connection string for your MongoDB database
appId: APP_ID,
masterKey: MASTER_KEY,
fileKey: 'optionalFileKey',
serverURL: 'http://localhost:1337/parse', // Don't forget to change to https if needed
push: {
android: {
senderId: GCM_SENDER_ID,
apiKey: GCM_API_KEY
},
ios: [
{
pfx: PFX_PATH_DEV, // The filename of private key and certificate in PFX or PKCS12 format from disk
passphrase: PFX_PASS_DEV, // optional password to your p12
bundleId: APP_BUNDLE_ID, // The bundle identifier associate with your app
production: false // Specifies which APNS environment to connect to: Production (if true) or Sandbox
const express = require('express');
const ParseServer = require('parse-server').ParseServer;
const app = express();
const port = process.env.PORT || 8080;
// Specify the connection string for your mongodb database
// and the location to your Parse cloud code
const parse = new ParseServer({
databaseURI: 'mongodb://localhost:27017/dev',
cloud: '/usr/src/parse/cloud/main.js',
appId: process.env.APP_ID,
masterKey: process.env.MASTER_KEY,
fileKey: process.env.FILE_KEY,
serverURL: 'http://localhost:1337/parse'
});
// Serve the Parse API on the /parse URL prefix
app.use('/parse', parse);
// Hello world
app.get('/', (req, res) => {
res.status(200).send('Express is running here.');
});
Parse.initialize(APP_ID);
Parse.serverURL = SERVER_URL;
Parse.masterKey = MASTER_KEY;
Parse.Cloud.useMasterKey();
if (cluster.isMaster) {
for (let i = 0; i < WORKERS; i += 1) {
cluster.fork();
}
} else {
const server = express();
server.use(
'/api',
new ParseServer({
databaseURI: DATABASE_URI,
cloud: path.resolve(__dirname, 'cloud.js'),
appId: APP_ID,
masterKey: MASTER_KEY,
serverURL: SERVER_URL,
})
);
let users = [];
if (DASHBOARD_USERS) {
DASHBOARD_USERS.split(',').map(u => {
let [user, pass] = u.split(':');
users.push({user, pass});
});
}
setup (app, appName, settings) {
Parse.initialize(settings.parseServerApplicationId, 'js-key', settings.parseServerMasterKey);
Parse.serverURL = settings.parseServerURL;
const api = new ParseServer({
appId: settings.parseServerApplicationId,
masterKey: settings.parseServerMasterKey,
serverURL: settings.parseServerURL,
databaseURI: settings.parseServerDatabaseURI
});
app.use('/parse', api);
app.use(
'/dashboard',
ParseDashboard({
apps: [{
serverURL: settings.parseServerURL,
appId: settings.parseServerApplicationId,
masterKey: settings.parseServerMasterKey,
appName,
if (!process.env.hasOwnProperty(env)) {
return;
}
var env_parameters = /^AUTH_([^_]*)_(.+)/.exec(env);
if (env_parameters !== null) {
if (typeof auth[env_parameters[1].toLowerCase()] === "undefined") {
auth[env_parameters[1].toLowerCase()] = {};
}
auth[env_parameters[1].toLowerCase()][env_parameters[2].toLowerCase()] = process.env[env];
}
}
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
databaseOptions: databaseOptions,
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'myAppId',
masterKey: process.env.MASTER_KEY, //Add your master key here. Keep it secret!
serverURL: serverURL,
collectionPrefix: process.env.COLLECTION_PREFIX,
clientKey: process.env.CLIENT_KEY,
restAPIKey: process.env.REST_API_KEY,
javascriptKey: process.env.JAVASCRIPT_KEY,
dotNetKey: process.env.DOTNET_KEY,
fileKey: process.env.FILE_KEY,
filesAdapter: filesAdapter,
serverURL: URL_SERVER,
publicServerURL: URL_SERVER
});
const cps = parseConfig.customPages;
for (let p in cps) {
cps[p] = URL_SITE + cps[p];
}
module.exports.parseConfig = parseConfig;
module.exports.URL_SITE = URL_SITE;
module.exports.StripeConfig = StripeConfig;
const API = new ParseServer(parseConfig);
const app = new express();
app.use('/parse', API);
if (DASHBOARD_ACTIVATED) {
const dashboardConfig = {
apps: [{
serverURL: URL_SERVER,
appId: APP_ID,
masterKey: MASTER_KEY,
appName: parseConfig.appName
}],
trustProxy: 1,
PARSE_DASHBOARD_ALLOW_INSECURE_HTTP: 1,
allowInsecureHTTP: 1
};
configureCommon(nconf, app, io) {
app.use(nconf.get('PARSE_PATH'), new ParseServer({
databaseURI: nconf.get('MONGO_URI') ? nconf.get('MONGO_URI') : 'mongodb://' + nconf.get('MONGO_HOST') + ':' + nconf.get('MONGO_PORT') + '/' + nconf.get('MONGO_DB'),
appId: nconf.get('PARSE_APPLICATION_ID'),
masterKey: nconf.get('PARSE_MASTER_KEY'),
serverURL: 'http://' + nconf.get('host') + ':' + nconf.get('port') + nconf.get('PARSE_PATH'),
}));
},