-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Change example to ES6 imports #400
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
Open
dblythy
wants to merge
4
commits into
parse-community:master
Choose a base branch
from
dblythy:es6-import
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
"no-await-in-loop" : 1 | ||
}, | ||
"globals" : { | ||
"Parse" : true | ||
"Parse" : true, | ||
"document": true | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,37 @@ | ||
// Example express application adding the parse-server module to expose Parse | ||
// compatible API routes. | ||
|
||
const express = require('express'); | ||
const ParseServer = require('parse-server').ParseServer; | ||
const path = require('path'); | ||
const args = process.argv || []; | ||
const test = args.some(arg => arg.includes('jasmine')); | ||
import express from 'express'; | ||
import { ParseServer } from 'parse-server'; | ||
import { createServer } from 'http'; | ||
import { config } from './src/config.js'; | ||
import { renderFile } from 'ejs'; | ||
|
||
const databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI; | ||
|
||
if (!databaseUri) { | ||
console.log('DATABASE_URI not specified, falling back to localhost.'); | ||
} | ||
const config = { | ||
databaseURI: databaseUri || 'mongodb://localhost:27017/dev', | ||
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: process.env.SERVER_URL || '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 | ||
}, | ||
}; | ||
// 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 | ||
|
||
const app = express(); | ||
export const app = express(); | ||
app.set('view engine', 'ejs'); | ||
app.engine('html', renderFile); | ||
app.set('views', `./src/views`); | ||
|
||
// Serve static assets from the /public folder | ||
app.use('/public', express.static(path.join(__dirname, '/public'))); | ||
app.use('/public', express.static('./src/public')); | ||
|
||
// Serve the Parse API on the /parse URL prefix | ||
const mountPath = process.env.PARSE_MOUNT || '/parse'; | ||
if (!test) { | ||
const api = new ParseServer(config); | ||
app.use(mountPath, api); | ||
} | ||
|
||
// Parse Server plays nicely with the rest of your web routes | ||
app.get('/', function (req, res) { | ||
res.status(200).send('I dream of being a website. Please star the parse-server repo on GitHub!'); | ||
res.render('test.html', { appId: config.appId, serverUrl: config.serverURL }); | ||
}); | ||
|
||
// There will be a test page available on the /test path of your server url | ||
// Remove this before launching your app | ||
app.get('/test', function (req, res) { | ||
res.sendFile(path.join(__dirname, '/public/test.html')); | ||
}); | ||
if (!process.env.TESTING) { | ||
const api = new ParseServer(config); | ||
app.use(mountPath, api); | ||
|
||
const port = process.env.PORT || 1337; | ||
if (!test) { | ||
const httpServer = require('http').createServer(app); | ||
const port = process.env.PORT || 1337; | ||
const httpServer = createServer(app); | ||
httpServer.listen(port, function () { | ||
console.log('parse-server-example running on port ' + port + '.'); | ||
console.log(`parse-server-example running on port ${port}.`); | ||
}); | ||
// This will enable the Live Query real-time server | ||
ParseServer.createLiveQueryServer(httpServer); | ||
} | ||
|
||
module.exports = { | ||
app, | ||
config, | ||
}; |
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
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.
I would rename
index
toserver.js
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 think it’s pretty common practise for index to be the main entry point for package.json