diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a3d4ae74b..9d8f921e29 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,12 +12,12 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [12.x] + node-version: [16.x] name: ${{ matrix.name }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - name: Install Dependancies diff --git a/cloud/main.js b/cloud/main.js index 7c8d64a859..6d2f55bff5 100644 --- a/cloud/main.js +++ b/cloud/main.js @@ -1,2 +1,2 @@ // It is best practise to organize your cloud functions group into their own file. You can then import them in your main.js. -require('./functions.js'); +await import('./functions.js'); diff --git a/index.js b/index.js index e720980bf0..2baf852c93 100644 --- a/index.js +++ b/index.js @@ -1,19 +1,15 @@ // 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')); - -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', +import express from 'express'; +import { ParseServer } from 'parse-server'; +import path from 'path'; +const __dirname = path.resolve(); +import http from 'http'; + +export const config = { + databaseURI: + process.env.DATABASE_URI || process.env.MONGODB_URI || '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! @@ -26,16 +22,17 @@ const config = { // 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(); // Serve static assets from the /public folder app.use('/public', express.static(path.join(__dirname, '/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); +if (!process.env.TESTING) { + const mountPath = process.env.PARSE_MOUNT || '/parse'; + const server = new ParseServer(config); + await server.start(); + app.use(mountPath, server.app); } // Parse Server plays nicely with the rest of your web routes @@ -49,17 +46,12 @@ app.get('/test', function (req, res) { res.sendFile(path.join(__dirname, '/public/test.html')); }); -const port = process.env.PORT || 1337; -if (!test) { - const httpServer = require('http').createServer(app); +if (!process.env.TESTING) { + const port = process.env.PORT || 1337; + const httpServer = http.createServer(app); httpServer.listen(port, function () { console.log('parse-server-example running on port ' + port + '.'); }); // This will enable the Live Query real-time server - ParseServer.createLiveQueryServer(httpServer); + await ParseServer.createLiveQueryServer(httpServer); } - -module.exports = { - app, - config, -}; diff --git a/package.json b/package.json index edcc175b17..c563070fb4 100644 --- a/package.json +++ b/package.json @@ -9,27 +9,29 @@ "license": "MIT", "main": "index.js", "scripts": { - "coverage": "nyc jasmine", + "coverage": "TESTING=true nyc jasmine", "lint": "eslint --cache ./cloud && eslint --cache index.js && eslint --cache ./spec", "lint-fix": "eslint --cache --fix ./cloud && eslint --cache --fix index.js && eslint --cache --fix ./spec", "prettier": "prettier --write '{cloud,spec}/{**/*,*}.js' 'index.js'", "start": "node index.js", - "test": "mongodb-runner start && jasmine", + "test": "mongodb-runner start && TESTING=true jasmine", "watch": "nodemon index.js" }, "dependencies": { - "express": "4.18.1", - "parse": "3.4.2", - "parse-server": "5.2.1" + "axios": "1.3.5", + "express": "4.18.2", + "parse": "4.0.1", + "parse-server": "6.0.0" }, + "type": "module", "devDependencies": { - "@babel/eslint-parser": "7.17.0", - "eslint": "8.15.0", - "jasmine": "4.1.0", - "mongodb-runner": "4.9.0", - "nodemon": "2.0.16", + "@babel/eslint-parser": "7.21.3", + "eslint": "8.38.0", + "jasmine": "4.6.0", + "mongodb-runner": "4.10.0", + "nodemon": "2.0.22", "nyc": "15.1.0", - "prettier": "2.6.2" + "prettier": "2.8.7" }, "engines": { "node": ">=12.22.10 <19" diff --git a/spec/Tests.spec.js b/spec/Tests.spec.js index 8893f067f8..dcd01f33ec 100644 --- a/spec/Tests.spec.js +++ b/spec/Tests.spec.js @@ -1,3 +1,4 @@ +import axios from 'axios'; describe('Parse Server example', () => { Parse.User.enableUnsafeCurrentUser(); it('call function', async () => { @@ -20,17 +21,13 @@ describe('Parse Server example', () => { } }); it('coverage for /', async () => { - const { text, headers } = await Parse.Cloud.httpRequest({ - url: 'http://localhost:30001/', - }); + const { data, headers } = await axios.get('http://localhost:30001/'); expect(headers['content-type']).toContain('text/html'); - expect(text).toBe('I dream of being a website. Please star the parse-server repo on GitHub!'); + expect(data).toBe('I dream of being a website. Please star the parse-server repo on GitHub!'); }); it('coverage for /test', async () => { - const { text, headers } = await Parse.Cloud.httpRequest({ - url: 'http://localhost:30001/test', - }); + const { data, headers } = await axios.get('http://localhost:30001/test'); expect(headers['content-type']).toContain('text/html'); - expect(text).toContain('