Skip to content

Error: "Unable to connect to 'http://localhost:1337/parse'" with NextJs (React) #7162

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

Closed
tiavina-mika opened this issue Feb 2, 2021 · 2 comments

Comments

@tiavina-mika
Copy link

I'm using a custome NextJs server with express and Parse Server.

here is my custom server:

`
/** ----------------------------------------------------- /
/
* ------------------- Custom Server ------------------- /
/
* ----------------------------------------------------- */

const express = require('express');
const dotenv = require('dotenv');
const next = require('next');
const path = require('path');

const { getParseServer, getParseDashboard } = require('./parse');

const dev = process.env.NODE_ENV !== 'production';

const port = 3000;

// Create the Express-Next App
const app = next({ dev });
const handle = app.getRequestHandler();

// ------------------------------------------------------------------------- //
// ------------------------ envvars initialisation ------------------------- //
// ------------------------------------------------------------------------- //
let envFileName;
if (dev) {
envFileName = '.env.local';
} else {
envFileName = '.env.prod';
}

dotenv.config({ path: path.join(__dirname, envFileName) });

app
.prepare()
.then(() => {
const server = express();

// ---- parse in express ----//
server.use('/parse', getParseServer());
if (dev) {
  server.use('/dashboard', getParseDashboard());
}

server.all('*', (req, res) => {
  return handle(req, res);
});

if (dev) {
  server.listen(port, (err) => {
    if (err) throw err;
    /* eslint-disable no-console */
    console.log(
      `> Server listening at http://localhost:${port} as ${
        dev ? 'development' : process.env.NODE_ENV
      }`,
    );
  });
} else {
  server.listen();
}

});
`

and here is the parse file initialization / configuration:

`
const { ParseServer } = require('parse-server');
const ParseDashboard = require('parse-dashboard');
const path = require('path');

// must be secrets
const APP_ID = 'increzia';
const MASTER_KEY = 'increziaApp';
const APP_NAME = 'Increzia';

const DASHBOARD_USER = 'michael';
const DASHBOARD_PASSWORD = 'michael';

const getServerUrl = () => ${process.env.HOST}:1337/parse;

const getParseServer = () => {
const DB_URL = process.env.DBURL;

const parseServerAPI = new ParseServer({
databaseURI: DB_URL,
cloud: path.resolve(__dirname, 'server/cloud/main.ts'),
appId: APP_ID,
masterKey: MASTER_KEY,
serverURL: getServerUrl(),
appName: APP_NAME,
});

return parseServerAPI;
};

const getParseDashboard = () => {
const dashboard = new ParseDashboard({
apps: [
{
serverURL: getServerUrl(),
appId: APP_ID,
masterKey: MASTER_KEY,
appName: APP_NAME,
},
],
users: [
{
user: DASHBOARD_USER,
pass: DASHBOARD_PASSWORD,
apps: [{ appId: APP_ID }],
},
],
});

return dashboard;
};

exports.getParseServer = getParseServer;
exports.getParseDashboard = getParseDashboard;
`

and my package.json scripts:

"scripts": { "dev": "next dev", "server": "node server.js", "reload": "nodemon server.js", "prod": "cross-env NODE_ENV=production node server.js", "build": "next build", "build-static": "next build & next export", "start": "next start", "lint": "eslint --fix . --ext .js,.jsx,.ts,.tsx", "storybook": "start-storybook -s ./public -p 6006", "build-storybook": "build-storybook --no-dll -s ./public" },

but I got this error:

WARNING, Unable to connect to 'http://localhost:1337/parse'. Cloud code and push notifications may be unavailable!

@dplewis dplewis transferred this issue from parse-community/Parse-SDK-JS Feb 3, 2021
@dplewis
Copy link
Member

dplewis commented Feb 3, 2021

I transferred this issue to the Server repository. Possible duplicate of #4506

Does GET http://localhost:1337/parse/health return status 200?

@mtrezza mtrezza changed the title Does someone use Parse in combination with NextJs (React)? Error: "Unable to connect to 'http://localhost:1337/parse'" with NextJs (React) Feb 3, 2021
@mtrezza
Copy link
Member

mtrezza commented Feb 10, 2021

I'm closing this as it lacks essential information required to investigate the issue. Please follow up on any questions asked and further steps suggested in the thread and we can re-open this issue.

@mtrezza mtrezza closed this as completed Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants