Parse-server POST instead of GET and no public access, migration config

Hi, I still get issues on parse-server migration

Now the problem is, no GET requests allowed for cloud functions, which requests data from classes that have public access, (besides I haven’t even touched to the database that I copied to mongodb.com which works at production right now)

How can I build the exact same setup like I have been using in moralis dashboard? App is ready to work well, but the new parse-server config is kind of primitive to run our app.

How can I set a new config for my parse-server?

I need to be able to send GET requests to be able to list the items for example. Even though I am refactoring, our app has multiple features that difficult to follow the errors where their exact sources.

I’m studying more about web2 and parse-server now but, could you help for this quicker way or guide me to a useful doc, would be appreciated

1 Like

Hi @atlasdev

Can you share how you found the cloud functions are using post request and not get request is allowed?
I thinks all cloud functions can be called through get request only.

hi @johnversus,

Here is the 2 screenshot together shows the only POST method gets accepted through parse-server.

__


__

Here’s my express engine (index.ts):

import Moralis from 'moralis';
import express from 'express';
import cors from 'cors';
import config from './config';
import { parseServer } from './parseServer';
// @ts-ignore
import ParseServer from 'parse-server';
import http from 'http';
import ngrok from 'ngrok';
import { streamsSync } from '@moralisweb3/parse-server';

export const app = express();

Moralis.start({
  apiKey: config.MORALIS_API_KEY,
});

app.use(express.urlencoded({ extended: true }));
app.use(express.json());

app.use(cors());

app.use(
  streamsSync(parseServer, {
    apiKey: config.MORALIS_API_KEY,
    webhookUrl: '/streams',
  }),
);

app.use(`/server`, parseServer.app);

app.use('/server/functions/:functionName', (req, res, next) => {
  req.headers['x-parse-application-id'] = config.APPLICATION_ID;
  next();
});

const httpServer = http.createServer(app);
httpServer.listen(config.PORT, async () => {
  if (config.USE_STREAMS) {
    const url = await ngrok.connect(config.PORT);
    // eslint-disable-next-line no-console
    console.log(
      `Moralis Server is running on port ${config.PORT} and stream webhook url ${url}${config.STREAMS_WEBHOOK_URL}`,
    );
  } else {
    // eslint-disable-next-line no-console
    console.log(`Moralis Server is running on port ${config.PORT}.`);
  }
});
// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);


__

And here’s the cloud code snippet./build/cloud/main.js

//...

Parse.Cloud.define('howManyItems', async () => {
    const query = new Parse.Query('ShowcaseItems');
    query.notEqualTo('published', false);
    const itemsLength = await query.count();
    return itemsLength;
});

//...

_

Even for that little snippet requires authentication at my migration app, which no needed in moralis servers.

that parse-server configuration from moralis’ free-prototype-app-servers would fix all totally I believe cos’ our app is seamlessly working there at the moment.

Thanks for your interest, I hope that won’t erodes tolarance much.

update:

I leared that parse-server doesn’t allow GET requests as default, which is alright, I can refactor the app to this fact. But now the application gets ws connection error for that line in index.ts: ParseServer.createLiveQueryServer(httpServer);

Btw, I noticed the new versions of

  • moralis@2.16.1
  • @moralisweb3/common-core@2.16.1
  • @moralisweb3/parse-server@2.16.1

they are coming as 2.14.3 in parse-migration package from github. Should I update them to latest?

Hi @atlasdev

sry I am not aware of this from parse server. I might have to dig more onto this.

If you have found a solution by upgrading then you can test it once by upgrading.

hi @johnversus thanks for your interest, I think this is only parse-server issue so moralis doesn’t want to be part of it, I see, I’m doing my research as far as I can go with it.

I did the test, updating moralis from 2.14.3 to up makes the migration app explode, couldn’t build from TS. it can’t deal with the new versions. I rolled back package.json to origins of the github folder.

I’ll try to deploy to heroku and try out in there only to understand if it’s all HTTPS issue or not.

wish me luck!

2 Likes

Hi, how are you? could you solve the problem? I try to store the data from the stream and when I receive the data and I have not been able to.

Thanks for asking @davidzuccarini, but I couldn’t understand your question well enough. Could you make your question again with more details?

Before your better question arrive first, this is parse-server thing, not Moralis. So I can reply to this topic only once in this forum and I could summarize a bit what I have achieved in here under this topic. So sent me DM in this forum for another issue if that will be only about parse-server.

My errors reasoned by that the parse-server can’t get application ID, so be sure that your app id is being sent via headers.

You need to add header field while calling cloud functions from the parse-server for it to recognize your app. For example, let’s assume you are using Firefox’s Web Developer Tools > Network Tab > REST Request Panel or similar tool like Postman, Insomnia etc., you must add x-parse-application-id header field with your app id to be able to call a cloud function well.

image

_

Your self-hosted database management app has main index.ts file, which runs ExpressJS backend management tool. You must add those lines into this index.ts file to make your public calls (POST) with your application id that’s been declared inside your .env file. e.g.:

...

// Declare application id through headers
app.use('/server/functions/:functionName', (req, res, next) => {
  req.headers['x-parse-application-id'] = config.APPLICATION_ID;
  next();
});

// before this:
const httpServer = http.createServer(app);
httpServer.listen(config.PORT, async () => {
...

_

So the topic was about that. Frankly, I couldn’t have time to design a middleware to hide my application id on REST requests yet. I assume it won’t be a security issue as long as class level securities adjusted well anyway, if anyone else think different I’d be appreciated to hear why.

_

You’d like to read this maybe: