如何在 nodeJs 服务器上正确使用 Forest Admin? (与森林快递猫鼬)

How to use Forest Admin properly with nodeJs server? (with forest-express-mongoose)

我正在尝试 运行 在我的笔记本电脑上本地使用 NodeJS 编程的服务器,并使用 forest-express-mongoose 包与 Forest Admin 交互。数据库是本地 MongoDB.

所以我 运行 我的服务器,它能够与我制作的完美应用程序连接。它也正确连接到 mongoDB 数据库。 那么我想使用 Forest Admin。 我对 Forest 不太熟悉,但我认为我不必将 Forest admin 安装为 npm 项目,因为这会创建另一个单独的项目,在这种情况下,我在我的服务器内部使用 forest-express-mongoose。 现在我不知道的是如何获得森林管理面板?

我的服务器 运行s 但它给了我一个错误,因为 env 密钥没有与任何森林面板相关联:(森林服务器请求错误:未找到)

这确实是预料之中的,因为我必须从 Forest 网站内部创建一个项目。但是当我想创建一个时,安装过程要我创建并安装另一个单独的服务器。那不是我想要的,我想将它与我现有的服务器集成。我怎样才能做到这一点?

这是我服务器的代码:

require('dotenv').config()

const express = require('express');
const bodyParser = require('body-parser');

// create express app
const app = express();

// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }))

// parse application/json
app.use(bodyParser.json())

// Configuring the database
const dbConfig = require('./config/database.config.js');
const mongoose = require('mongoose');

const cors = require('cors');

mongoose.Promise = global.Promise;

// Connecting to the database
mongoose.connect(process.env.MONGODB_URI || dbConfig.url, {
    useNewUrlParser: true
}).then(() => {
    console.log("Successfully connected to the database");
}).catch(err => {
    console.log('Could not connect to the database. Exiting now...', err);
    process.exit();
});

// define a simple route
app.get('/', (req, res) => {
    res.json({"message": "Welcome to EasyDonations application. Take donations quickly. Organize and keep track of all your donations."});
});

// Then use it before your routes are set up:
app.use(cors({credentials: true, origin: true}));

require('./app/models/timeframe.js');
require('./app/routes/institution.routes.js')(app);
require('./app/routes/offer.routes.js')(app);
require('./app/routes/request.routes.js')(app);
require('./app/routes/user.routes.js')(app);
require('./app/routes/volunteer.routes.js')(app);
require('./app/routes/donation.routes.js')(app);

// listen for requests
app.listen(process.env.PORT || 3000, () => {
    console.log("Server is listening on port 3000");
});

app.use(require('forest-express-mongoose').init({
    modelsDir: __dirname + '/app/models',
    envSecret: 'xxx', // the key I obviously don't have
    authSecret: 'testeando', // I think I can put any string for development purposes, otherwise I don't know were to get authSecret
    mongoose: require('mongoose'),
}));

我的 package.json 具有以下依赖项:

"dependencies": {
  "async": "^2.6.2",
  "body-parser": "^1.18.3",
  "cors": "^2.8.5",
  "dotenv": "^6.2.0",
  "express": "^4.16.4",
  "forest-express-mongoose": "^2.16.1",
  "mongodb": "^3.1.13",
  "mongoose": "5.1.4",
  "mongoose-schema-extend": "^0.2.2"
}

我知道我正在使用一些旧的依赖项,但如果我开始更改它们,项目就会开始出现问题。

所以我有点陷入恶性循环。我需要创建森林管理员以使我的服务器正常工作,但森林管理员创建过程要我创建一个单独的服务器。

或者我可能还需要 运行 一个森林服务器?我试过了,结果是如果我 运行 森林首先它从我的数据库获取数据但是当我 运行 我的服务器它改变它的模型并且它给我一个错误“服务器遇到错误”。

我设法 运行 我的服务器在简单地 运行 连接它之后在一个已经创建的森林项目上设置了一个新环境,其服务器设置为 http://localhost:3000