11// Example express application adding the parse-server module to expose Parse
22// compatible API routes.
33
4- const express = require ( 'express' ) ;
5- const ParseServer = require ( 'parse-server' ) . ParseServer ;
6- const path = require ( 'path' ) ;
7- const args = process . argv || [ ] ;
8- const test = args . some ( arg => arg . includes ( 'jasmine' ) ) ;
9-
10- const databaseUri = process . env . DATABASE_URI || process . env . MONGODB_URI ;
11-
12- if ( ! databaseUri ) {
13- console . log ( 'DATABASE_URI not specified, falling back to localhost.' ) ;
14- }
15- const config = {
16- databaseURI : databaseUri || 'mongodb://localhost:27017/dev' ,
4+ import express from 'express' ;
5+ import { ParseServer } from 'parse-server' ;
6+ import path from 'path' ;
7+ const __dirname = path . resolve ( ) ;
8+ import http from 'http' ;
9+
10+ export const config = {
11+ databaseURI :
12+ process . env . DATABASE_URI || process . env . MONGODB_URI || 'mongodb://localhost:27017/dev' ,
1713 cloud : process . env . CLOUD_CODE_MAIN || __dirname + '/cloud/main.js' ,
1814 appId : process . env . APP_ID || 'myAppId' ,
1915 masterKey : process . env . MASTER_KEY || '' , //Add your master key here. Keep it secret!
@@ -26,16 +22,17 @@ const config = {
2622// If you wish you require them, you can set them as options in the initialization above:
2723// javascriptKey, restAPIKey, dotNetKey, clientKey
2824
29- const app = express ( ) ;
25+ export const app = express ( ) ;
3026
3127// Serve static assets from the /public folder
3228app . use ( '/public' , express . static ( path . join ( __dirname , '/public' ) ) ) ;
3329
3430// Serve the Parse API on the /parse URL prefix
35- const mountPath = process . env . PARSE_MOUNT || '/parse' ;
36- if ( ! test ) {
37- const api = new ParseServer ( config ) ;
38- app . use ( mountPath , api ) ;
31+ if ( ! process . env . TESTING ) {
32+ const mountPath = process . env . PARSE_MOUNT || '/parse' ;
33+ const server = new ParseServer ( config ) ;
34+ await server . start ( ) ;
35+ app . use ( mountPath , server . app ) ;
3936}
4037
4138// Parse Server plays nicely with the rest of your web routes
@@ -49,17 +46,12 @@ app.get('/test', function (req, res) {
4946 res . sendFile ( path . join ( __dirname , '/public/test.html' ) ) ;
5047} ) ;
5148
52- const port = process . env . PORT || 1337 ;
53- if ( ! test ) {
54- const httpServer = require ( ' http' ) . createServer ( app ) ;
49+ if ( ! process . env . TESTING ) {
50+ const port = process . env . PORT || 1337 ;
51+ const httpServer = http . createServer ( app ) ;
5552 httpServer . listen ( port , function ( ) {
5653 console . log ( 'parse-server-example running on port ' + port + '.' ) ;
5754 } ) ;
5855 // This will enable the Live Query real-time server
59- ParseServer . createLiveQueryServer ( httpServer ) ;
56+ await ParseServer . createLiveQueryServer ( httpServer ) ;
6057}
61-
62- module . exports = {
63- app,
64- config,
65- } ;
0 commit comments