Running Dash and server from Example as express middleware

I have downloaded the example and updated it - to include Dashboard as express middleware as below

it loads and looks like /api is the server and /dashboard is the dashboard - when I login to dashboard it shows the APP list BUT says Server not reachable: Invalid server state: initialized

when I look at the chrome network it says {“code”:1,“error”:“Invalid server state: initialized”}

Help ! >>

import express from ‘express’;
import { ParseServer } from ‘parse-server’;
import ParseDashboard from ‘parse-dashboard’;
import dotenv from ‘dotenv’;
import path from ‘path’;
import { fileURLToPath } from ‘url’;

// Load environment variables
dotenv.config();

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const app = express();

// Parse Server configuration
const parseServerConfig = {
databaseURI: process.env.DATABASE_URI || ‘mongodb://localhost:27017/dena’,
cloud: process.env.CLOUD_CODE_MAIN || path.join(__dirname, ‘/cloud/main.js’),
appId: process.env.APP_ID || ‘dena’,
masterKey: process.env.MASTER_KEY || ‘myMasterKey’, // Keep this secret
serverURL: process.env.SERVER_URL || ‘http://127.0.0.1:1337/api’, // URL of your Parse Server
publicServerURL: process.env.PUBLIC_SERVER_URL || ‘http://127.0.0.1:1337’,
appName: process.env.APP_NAME || ‘dena’,
logLevel: process.env.LOG_LEVEL || ‘info’,
// Removed invalid options: serverInfo and allowOrigins
emailAdapter: {
module: ‘simple-parse-smtp-adapter’,
options: {
fromAddress: process.env.EMAIL_FROM_ADDRESS,
user: process.env.EMAIL_USERNAME,
password: process.env.EMAIL_PASSWORD,
host: process.env.EMAIL_SMTP,
isSSL: process.env.EMAIL_SSL === ‘true’,
port: parseInt(process.env.EMAIL_PORT) || 465,
name: process.env.EMAIL_NAME,
},
},
};

console.log (parseServerConfig);

// Create a new Parse Server instance
const parseServer = new ParseServer(parseServerConfig);

// Serve the Parse API on the /api URL prefix
app.use(process.env.PARSE_SERVER_MOUNT || ‘/api’, parseServer.app); // Correct way to pass Parse Server as middleware

// Parse Dashboard configuration
const dashboardConfig = {
apps: [
{
serverURL: process.env.SERVER_URL || ‘http://127.0.0.1:1337/api’,
appId: process.env.APP_ID || ‘dena’,
masterKey: process.env.MASTER_KEY || ‘myMasterKey’,
appName: process.env.APP_NAME || ‘dena’,
readOnlyMasterKey: process.env.READ_ONLY_MASTER_KEY
},
],
users: [
{
user: process.env.PARSE_DASHBOARD_USER || ‘admin’,
pass: process.env.PARSE_DASHBOARD_PASS || ‘password’,
},
{
user: process.env.PARSE_DASHBOARD_USER_READ_ONLY || ‘readonly’,
pass: process.env.PARSE_DASHBOARD_PASS_READ_ONLY || ‘readonlypass’,
readOnly: true,
},
],
useEncryptedPasswords: false, // Set to true if passwords are encrypted
allowInsecureHTTP: true, // Set to true only for development; for production, use HTTPS
trustProxy: 1
};

console.log (dashboardConfig);

// Create a new Parse Dashboard instance
const dashboard = new ParseDashboard(dashboardConfig);

// Serve the dashboard at /dashboard
app.use(‘/dashboard’, dashboard);

// Start the server
const port = process.env.PORT || 1337;
const httpServer = app.listen(port, () => {
console.log(Server running on port ${port});
console.log(Parse Server running on ${process.env.SERVER_URL});
console.log(Parse Dashboard running on http://localhost:${port}/dashboard);
});

// Enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);

export default app;

Start the parse server

await parseServer.start()

1 Like

F…n genius - thank you :slight_smile: that worked.

1 Like