44import express from 'express' ;
55import { ParseServer } from 'parse-server' ;
66import path from 'path' ;
7- const __dirname = path . resolve ( ) ;
87import http from 'http' ;
9-
10- export const config = {
11- databaseURI :
12- process . env . DATABASE_URI || process . env . MONGODB_URI || 'mongodb://localhost:27017/dev' ,
13- cloud : process . env . CLOUD_CODE_MAIN || __dirname + '/cloud/main.js' ,
14- appId : process . env . APP_ID || 'myAppId' ,
15- masterKey : process . env . MASTER_KEY || '' , //Add your master key here. Keep it secret!
16- serverURL : process . env . SERVER_URL || 'http://localhost:1337/parse' , // Don't forget to change to https if needed
17- liveQuery : {
18- classNames : [ 'Posts' , 'Comments' ] , // List of classes to support for query subscriptions
19- } ,
20- } ;
21- // Client-keys like the javascript key or the .NET key are not necessary with parse-server
22- // If you wish you require them, you can set them as options in the initialization above:
23- // javascriptKey, restAPIKey, dotNetKey, clientKey
24-
25- export const app = express ( ) ;
26-
27- app . set ( 'trust proxy' , true ) ;
8+ import { config } from './config.js' ;
9+ const __dirname = path . resolve ( ) ;
10+ const app = express ( ) ;
2811
2912// Serve static assets from the /public folder
3013app . use ( '/public' , express . static ( path . join ( __dirname , '/public' ) ) ) ;
3114
3215// Serve the Parse API on the /parse URL prefix
33- if ( ! process . env . TESTING ) {
34- const mountPath = process . env . PARSE_MOUNT || '/parse' ;
35- const server = new ParseServer ( config ) ;
36- await server . start ( ) ;
37- app . use ( mountPath , server . app ) ;
38- }
16+ const mountPath = process . env . PARSE_MOUNT || '/parse' ;
17+ const server = new ParseServer ( config ) ;
18+ await server . start ( ) ;
19+ app . use ( mountPath , server . app ) ;
3920
4021// Parse Server plays nicely with the rest of your web routes
4122app . get ( '/' , function ( req , res ) {
@@ -48,12 +29,11 @@ app.get('/test', function (req, res) {
4829 res . sendFile ( path . join ( __dirname , '/public/test.html' ) ) ;
4930} ) ;
5031
51- if ( ! process . env . TESTING ) {
52- const port = process . env . PORT || 1337 ;
53- const httpServer = http . createServer ( app ) ;
54- httpServer . listen ( port , function ( ) {
55- console . log ( 'parse-server-example running on port ' + port + '.' ) ;
56- } ) ;
57- // This will enable the Live Query real-time server
58- await ParseServer . createLiveQueryServer ( httpServer ) ;
59- }
32+ const port = process . env . PORT || 1337 ;
33+ const httpServer = http . createServer ( app ) ;
34+ httpServer . listen ( port , function ( ) {
35+ console . log ( 'parse-server-example running on port ' + port + '.' ) ;
36+ } ) ;
37+ // This will enable the Live Query real-time server
38+ await ParseServer . createLiveQueryServer ( httpServer ) ;
39+ console . log ( `Visit http://localhost:${ port } /test to check the Parse Server` ) ;
0 commit comments