Created
October 26, 2019 13:12
-
-
Save satyajeetjadhav/f2ddf421fad8c45e969d7838786d18b9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Example express application adding the parse-server module to expose Parse | |
// compatible API routes. | |
var express = require('express'); | |
var ParseServer = require('parse-server').ParseServer; | |
var path = require('path'); | |
var compression = require('compression'); | |
var S3Adapter = require('@parse/s3-files-adapter'); | |
var oembed = require('./oembed.js'); | |
var getTrip = require('./getTrip.js'); | |
var cors = require('cors'); | |
var request = require('request'); // npm install request | |
var multer = require('multer'); | |
var upload = multer().any(); | |
var SimpleSendGridAdapter = require('parse-server-sendgrid-adapter'); | |
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI; | |
var SENDGRID_API_KEY = 'SG.-Sw2HRAyTGKFexrlvT2Ozw.nordBICRSxaUEjlrrwuudtKwpYClAEurSN6nTr6iwZw'; | |
//if (!databaseUri) { | |
// console.log('DATABASE_URI not specified, falling back to localhost.'); | |
//} | |
var api = new ParseServer({ | |
databaseURI: '<your MONGO DB URI>', | |
cloud: __dirname + '/cloud/main.js', | |
appId: <SOME_RANDOM_STRING>, | |
masterKey: <SOME_RANDOM_STRING>, //Add your master key here. Keep it secret! | |
serverURL: 'https://api.hopbucket.com/parse', // Don't forget to change to https if needed | |
liveQuery: { | |
classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions | |
}, | |
filesAdapter: new S3Adapter( | |
accessKey, | |
secretKey, | |
BUCKET_NAME, { | |
directAccess: true | |
} | |
), | |
appName: "HopBucket", | |
publicServerURL: 'https://api.hopbucket.com/parse', | |
emailAdapter: SimpleSendGridAdapter({ | |
apiKey: SENDGRID_API_KEY, | |
fromAddress: '[email protected]', | |
}), | |
// Mail Adapter | |
verifyUserEmails: true, | |
emailVerifyTokenValidityDuration: 2 * 60 * 60, | |
}); | |
// Client-keys like the javascript key or the .NET key are not necessary with parse-server | |
// If you wish you require them, you can set them as options in the initialization above: | |
// javascriptKey, restAPIKey, dotNetKey, clientKey | |
var app = express(); | |
/* app.use(express.json()); | |
app.use(express.urlencoded({ | |
extended: false | |
})); */ | |
var bodyParser = require('body-parser'); | |
app.use(bodyParser.json({ limit: '50mb' })); | |
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true })); | |
app.use(compression()); | |
// Serve the Parse API on the /parse URL prefix | |
var mountPath = process.env.PARSE_MOUNT || '/parse'; | |
app.use(mountPath, api); | |
//for oembed urls: | |
var corsOptions = { | |
origin: '*', | |
optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204 | |
methods: "GET", | |
allowedHeaders: 'Origin, Content-Type, Accept', | |
exposedHeaders: 'User-Agent' | |
} | |
var port = process.env.PORT || 1337; | |
var httpServer = require('http').createServer(app); | |
httpServer.listen(port, function () { | |
console.log('parse-server-example running on port ' + port + '.'); | |
}); | |
var enforceHTTPS = function (req, res, next) { | |
if (req.headers['x-forwarded-proto'] === 'https') return next(); | |
return res.redirect(301, 'https://' + req.hostname + req.url); | |
}; | |
app.use(enforceHTTPS); | |
app.all('/*', function (req, res, next) { | |
// Just send the index.html for other files to support HTML5Mode | |
res.sendFile('index.html', { | |
root: path.join(__dirname, '/public') | |
}); | |
}); | |
// This will enable the Live Query real-time server | |
ParseServer.createLiveQueryServer(httpServer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment