我有一个Feathers.js后端,我一直在尝试使用ArangoDB data-adapter进行配置。
我的数据库仅使用默认的用户名,空白密码和名为test
的数据库,所有这些都在环境变量中设置。
ARANGODB_HOST="127.0.0.1"
ARANGODB_PASSWORD=""
ARANGODB_USERNAME="root"
ARANGODB_PORT=8529
ARANGODB_DB="test"
启动节点服务器时,出现以下错误
info: Feathers application started on http://localhost:3030
error: Unhandled Rejection at: Promise
似乎数据库未正确连接到Feathers.js或正在拒绝连接。我已经能够使用节点cli直接与ArangoDB接口,所以我认为这不是权限问题。该错误来自arangodb.js
的最后一行,但我不知道是什么原因导致了此错误,并且在网上搜索解决方案并没有发现任何问题。
我有以下文件:
/src/arangodb.js
const Database = require('arangojs').Database;
module.exports = function () {
const app = this;
const config = app.get('arangodb');
const promise = dbConnect(config);
app.set('arangoClient', promise);
};
function dbConnect (options = {}) {
const host = options.host || process.env.ARANGODB_HOST;
const port = options.port || process.env.ARANGODB_PORT;
const databaseName = options.database || process.env.ARANGODB_DB;
const basicAuth = options.basicAuth || {};
const username = basicAuth.username || process.env.ARANGODB_USERNAME;
const password = basicAuth.password || process.env.ARANGODB_PASSWORD;
const url = `${host}:${port}`;
const db = new Database(url);
db.useDatabase(databaseName);
if (username) db.useBasicAuth(username, password);
return new Promise((resolve, reject) => {
db.get()
.then(() => resolve(db))
.catch(err => reject(err));
});
}
/src/app.js
const path = require('path');
const favicon = require('serve-favicon');
const compress = require('compression');
const helmet = require('helmet');
const cors = require('cors');
const logger = require('./logger');
const feathers = require('@feathersjs/feathers');
const configuration = require('@feathersjs/configuration');
const express = require('@feathersjs/express');
const socketio = require('@feathersjs/socketio');
const middleware = require('./middleware');
const services = require('./services');
const appHooks = require('./app.hooks');
const channels = require('./channels');
const authentication = require('./authentication');
const sequelize = require('./sequelize');
const app = express(feathers());
// Load app configuration
app.configure(configuration());
// Enable security, CORS, compression, favicon and body parsing
app.use(helmet());
app.use(cors());
app.use(compress());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(favicon(path.join(app.get('public'), 'favicon.ico')));
// Host the public folder
app.use('/', express.static(app.get('public')));
// Set up Plugins and providers
app.configure(express.rest());
app.configure(socketio());
app.configure(sequelize);
// Configure other middleware (see `middleware/index.js`)
app.configure(middleware);
app.configure(authentication);
// Set up our services (see `services/index.js`)
app.configure(services);
// Set up event channels (see channels.js)
app.configure(channels);
const arangodb = require('./arangodb');
app.configure(arangodb);
// Configure a middleware for 404s and the error handler
app.use(express.notFound());
app.use(express.errorHandler({ logger }));
app.hooks(appHooks);
module.exports = app;