1
1
// Example express application adding the parse-server module to expose Parse
2
2
// compatible API routes.
3
3
4
- var express = require ( 'express' ) ;
5
- var ParseServer = require ( 'parse-server' ) . ParseServer ;
6
- var path = require ( 'path' ) ;
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' ) ) ;
7
9
8
- var databaseUri = process . env . DATABASE_URI || process . env . MONGODB_URI ;
10
+ const databaseUri = process . env . DATABASE_URI || process . env . MONGODB_URI ;
9
11
10
12
if ( ! databaseUri ) {
11
13
console . log ( 'DATABASE_URI not specified, falling back to localhost.' ) ;
12
14
}
13
-
14
- var api = new ParseServer ( {
15
+ const config = {
15
16
databaseURI : databaseUri || 'mongodb://localhost:27017/dev' ,
16
17
cloud : process . env . CLOUD_CODE_MAIN || __dirname + '/cloud/main.js' ,
17
18
appId : process . env . APP_ID || 'myAppId' ,
@@ -20,19 +21,22 @@ var api = new ParseServer({
20
21
liveQuery : {
21
22
classNames : [ "Posts" , "Comments" ] // List of classes to support for query subscriptions
22
23
}
23
- } ) ;
24
+ } ;
24
25
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
25
26
// If you wish you require them, you can set them as options in the initialization above:
26
27
// javascriptKey, restAPIKey, dotNetKey, clientKey
27
28
28
- var app = express ( ) ;
29
+ const app = express ( ) ;
29
30
30
31
// Serve static assets from the /public folder
31
32
app . use ( '/public' , express . static ( path . join ( __dirname , '/public' ) ) ) ;
32
33
33
34
// Serve the Parse API on the /parse URL prefix
34
- var mountPath = process . env . PARSE_MOUNT || '/parse' ;
35
- app . use ( mountPath , api ) ;
35
+ const mountPath = process . env . PARSE_MOUNT || '/parse' ;
36
+ if ( ! test ) {
37
+ const api = new ParseServer ( config ) ;
38
+ app . use ( mountPath , api ) ;
39
+ }
36
40
37
41
// Parse Server plays nicely with the rest of your web routes
38
42
app . get ( '/' , function ( req , res ) {
@@ -45,11 +49,17 @@ app.get('/test', function(req, res) {
45
49
res . sendFile ( path . join ( __dirname , '/public/test.html' ) ) ;
46
50
} ) ;
47
51
48
- var port = process . env . PORT || 1337 ;
49
- var httpServer = require ( 'http' ) . createServer ( app ) ;
50
- httpServer . listen ( port , function ( ) {
52
+ const port = process . env . PORT || 1337 ;
53
+ if ( ! test ) {
54
+ const httpServer = require ( 'http' ) . createServer ( app ) ;
55
+ httpServer . listen ( port , function ( ) {
51
56
console . log ( 'parse-server-example running on port ' + port + '.' ) ;
52
- } ) ;
57
+ } ) ;
58
+ // This will enable the Live Query real-time server
59
+ ParseServer . createLiveQueryServer ( httpServer ) ;
60
+ }
53
61
54
- // This will enable the Live Query real-time server
55
- ParseServer . createLiveQueryServer ( httpServer ) ;
62
+ module . exports = {
63
+ app,
64
+ config
65
+ } ;
0 commit comments