Parse Server & Parse Dashboard 部署指南(Node.js 环境)
Parse Server 是一款开源后端框架,可部署在任何支持 Node.js 的环境中;Parse Dashboard 是配套的可视化管理面板,用于便捷管理 Parse Server 应用。本文基于 MongoDB 环境,详细介绍两者的整合部署步骤。
一、前置依赖:安装 MongoDB
Parse Server 依赖 MongoDB 存储数据,需先完成 MongoDB 安装,可参考往期教程:
linux系统下安装mongodb
二、核心部署代码(index.js)
创建项目入口文件 index.js,整合 Parse Server 和 Parse Dashboard 的配置与启动逻辑:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| const express = require('express'); const ParseServer = require('parse-server').ParseServer; const ParseDashboard = require('parse-dashboard'); const http = require('http');
const appId = '1000'; const masterKey = '2000';
const parseServer = new ParseServer({ databaseURI: 'mongodb://localhost:27017/dev', appId: appId, masterKey: masterKey, fileKey: 'optionalFileKey', serverURL: 'http://localhost:4040/parse' });
const dashboardOptions = { allowInsecureHTTP: true }; const parseDashboard = new ParseDashboard({ apps: [ { serverURL: 'http://localhost:4040/parse', appId: appId, masterKey: masterKey, appName: 'app' } ], users: [ { user: 'cs', pass: '******', apps: [{ appId: appId }] }, { user: 'yh', pass: '******', apps: [{ appId: appId }] } ], trustProxy: 1 }, dashboardOptions);
const app = express(); app.use('/parse', parseServer); app.use('/dashboard', parseDashboard);
const httpServer = http.createServer(app); httpServer.listen(4040, () => { console.log('Parse Server & Dashboard 启动成功!'); console.log('Parse Server 地址:http://localhost:4040/parse'); console.log('Parse Dashboard 地址:http://localhost:4040/dashboard'); });
|
三、云函数扩展(cloud/main.js)
创建云函数目录及文件 cloud/main.js,用于扩展 Parse Server 自定义业务逻辑:
1 2 3 4
| Parse.Cloud.define('hello', function(req, res) { return 'Hi'; });
|
四、启动服务
开发环境推荐使用 nodemon 启动(代码修改后自动重启),需先完成 nodemon 安装(参考:nodemon 使用教程):
五、官方文档参考
总结
- Parse Server 依赖 MongoDB,部署前需确保数据库已安装并正常运行;
masterKey 是核心敏感信息,生产环境需严格保密,且建议启用 HTTPS(关闭 allowInsecureHTTP);
- Parse Dashboard 支持多用户权限配置,可根据团队需求添加/调整用户;
- 开发环境使用 nodemon 启动服务,可提升代码迭代效率,生产环境建议使用 PM2 等进程守护工具。