Skip to content
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

Parse is not a singleton anymore > v2.8.0 #966

Closed
JeffGuKang opened this issue Oct 24, 2019 · 3 comments
Closed

Parse is not a singleton anymore > v2.8.0 #966

JeffGuKang opened this issue Oct 24, 2019 · 3 comments
Labels
state:duplicate Duplicate of already reported issue

Comments

@JeffGuKang
Copy link
Contributor

JeffGuKang commented Oct 24, 2019

Issue Description

index.js

... // Parse config and initialize

initSchema() // Try set Parse.Schema in the end of file

schema.js

import Parse from 'parse/node'

const initSchema = async () => {
  try {
    const userInfo = await new Parse.Schema('UserInfo').get()
    console.log('initSchema: ', userInfo)
  }
...

}

It had no problem until v2.7.1 . And Parse worked as singleton.
But import Parse from 'parse/node' looks to create new Parse instance in v2.8.0.
So we need to use Parse as global variable without import after v2.8.0.

Is there any changes from v2.8.0 release related?

Steps to reproduce

Expected Results

Actual Outcome

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : [3.9.0]
    • Operating System: [Mac OS]
    • Hardware: [FILL THIS OUT]
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): [Localhost]
  • JS SDK

    • JS SDK version: [2.8.0]
    • Application? (Browser, Node, React-Native, etc): [Node]

Logs/Trace

(node:13984) UnhandledPromiseRejectionWarning: Error: Cannot use the Master Key, it has not been provided.
@dplewis
Copy link
Member

dplewis commented Oct 26, 2019

I don't believe such changes were made in 2.8.0.

Are you running this in cloud code? If so you don't need to import Parse

@JeffGuKang
Copy link
Contributor Author

JeffGuKang commented Oct 27, 2019

Cloud code is also. So I remove all import parse from cloud code.
and this happens in another files as below.

index.js

'use strict'

import dotenv from 'dotenv'
dotenv.config()

const ParseServer = require('parse-server').ParseServer
import express from 'express'
import ParseDashboard from 'parse-dashboard'
import path from 'path'
import {initSchema} from './src/schema' /************ Here **************/

const app = express()

// mongodb://username:password@ggg.com:27017/dbname
let databaseURI = process.env.LOCAL_DB_URI

// Specify the connection string for your mongodb database
// and the location to your Parse cloud code
const api = new ParseServer({
  databaseURI,
  cloud: __dirname + '/src/cloud/', // location after tsc
  appId: process.env.APP_ID,
  masterKey: process.env.MASTER_KEY,
  fileKey: process.env.FILE_KEY,
  serverURL: 'http://localhost:1337/parse', // Don't forget to add this line to change port or url
  // enableAnonymousUsers: true,
  liveQuery: {
    // classNames: ['Alram'],
  },
})

// Serve static assets from the /public folder
app.use('/', express.static(path.join(__dirname, '/public')))

// Serve the Parse API on the /parse URL prefix
app.use(process.env.PARSE_API_PREFIX, api)

// Hello world
// app.get('/', function(req, res) {
//   res.status(200).send('Init.');
// });

const httpServer = require('http').createServer(app) // Need for livequery
const port = process.env.PORT
httpServer.listen(port, function() {
  console.log('parse-server running on port %s', port)
})

ParseServer.createLiveQueryServer(httpServer)

initSchema() //************ Here **************/

.src/schema.js

import Parse from 'parse/node' // Import makes a problem in parse > v2.8.0 

const initSchema = async () => {
  try {
        new Parse.Schema('UserInfo').save({useMasterKey: true}),
    }
  } catch (error) {
    throw error
  }
}

export {initSchema}

Anyway, I resolved this issue to do not import parse.

@dplewis
Copy link
Member

dplewis commented Oct 27, 2019

Duplicate parse-community/parse-server#5278

@dplewis dplewis closed this as completed Oct 27, 2019
@dplewis dplewis added the state:duplicate Duplicate of already reported issue label Sep 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:duplicate Duplicate of already reported issue
Projects
None yet
Development

No branches or pull requests

2 participants