gpt4 book ai didi

mongodb - API 错误 : Error: connect ECONNREFUSED 127. 0.0.1:389 Apollo-React MongoDB

转载 作者:行者123 更新时间:2023-12-05 06:36:32 26 4
gpt4 key购买 nike

我正在尝试在 Windows 环境中使用 Apollo(GraphQL)、React、Webpack 和 MongoDB 运行 API 服务。服务启动成功,但是当我发送第一个请求时服务崩溃了。

我正在使用这个版本:

  • npm v5.6.0
  • 节点 v8.9.4
  • webpack v3.8.1
  • webpack-dev-server v3.0.0
  • apollo-server v^0.3.3
  • apollo-upload-server v^4.0.0-alpha.3
  • mongodb v^2.2.33

这是服务启动时的输出:

C:\test-dev3\name_app\api>npm run start

Webpack is watching the files…

Hash: fec0c0aa558d4a8b3bf7
Version: webpack 3.10.0
Time: 2388ms
Asset Size Chunks Chunk Names
server.bundle.js 94.3 kB 0 [emitted] server
[./node_modules/webpack/hot/log-apply-result.js] (webpack)/hot/log-apply-result.js 1.31 kB {0} [built]
[./node_modules/webpack/hot/log.js] (webpack)/hot/log.js 1.04 kB {0} [built]
[./node_modules/webpack/hot/poll.js?1000] (webpack)/hot/poll.js?1000 1.16 kB {0} [built]
[./src/carouselItem/schema.js] ./src/carouselItem/schema.js 4.96 kB {0} [built]
[./src/connectors/mongodb.js] ./src/connectors/mongodb.js 2.06 kB {0} [built]
[./src/context.js] ./src/context.js 706 bytes {0} [built]
[./src/index.js] ./src/index.js 451 bytes {0} [built]
[./src/options.js] ./src/options.js 786 bytes {0} [built]
[./src/schema.js] ./src/schema.js 975 bytes {0} [built]
[./src/server.js] ./src/server.js 3.45 kB {0} [built]
[./src/site/models.js] ./src/site/models.js 624 bytes {0} [built]
[./src/site/schema.js] ./src/site/schema.js 1.65 kB {0} [built]
[./src/user/models.js] ./src/user/models.js 2.81 kB {0} [built]
[./src/user/schema.js] ./src/user/schema.js 1.64 kB {0} [built]
[0] multi webpack/hot/poll?1000 ./src/index.js 40 bytes {0} [built]
+ 33 hidden modules
Options file loaded
Connected to mongoDB [object Object]
GraphQL-server listening on port 3000.

当服务崩溃时:

events.js:183
throw er; // Unhandled 'error' event
^

Error: connect ECONNREFUSED 127.0.0.1:389
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)

package.json:

{
"name": "name_app",
"version": "1.0.0",
"description": "API to expose",
"main": "lib/index.js",
"scripts": {
"start": "webpack --config webpack/config/dev.config.js",
},
"repository": {
"type": "",
"url": ""
},
"keywords": [
],
"author": "",
"license": "",
"bugs": {
"url": ""
},
"homepage": "",
"eslintIgnore": [
"**/node_modules/**",
"**/dist/**"
],
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-eslint": "^8.0.1",
"babel-loader": "^7.1.2",
"babel-plugin-transform-regenerator": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.26.0",
"copy-webpack-plugin": "^4.3.1",
"eslint": "^4.9.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jest": "^21.2.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-react": "^7.4.0",
"rimraf": "^2.6.2",
"start-server-webpack-plugin": "^2.2.0",
"uglifyjs-webpack-plugin": "^1.1.6",
"webpack": "^3.8.1",
"webpack-dev-server": "^3.0.0",
"webpack-node-externals": "^1.6.0"
},
"dependencies": {
"apollo-server": "^0.3.3",
"apollo-upload-server": "^4.0.0-alpha.3",
"bcryptjs": "^2.4.3",
"bluebird": "^3.5.1",
"body-parser": "^1.18.2",
"cors": "^2.8.4",
"express": "^4.16.2",
"graphql": "^0.11.7",
"graphql-tools": "^2.6.1",
"jsonwebtoken": "^8.1.1",
"ldapjs": "^1.0.2",
"lowdb": "^1.0.0",
"mkdirp": "^0.5.1",
"mongodb": "^2.2.33",
"mongoose": "^4.12.4",
"promise-ftp": "^1.3.4",
"promises-all": "^1.0.0",
"ramda": "^0.25.0",
"shortid": "^2.2.8"
}
}

网络包配置:

const webpack = require('webpack');
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const StartServerPlugin = require('start-server-webpack-plugin');
const SERVER_ENTRY_NAME = 'server';
const BUILD_FOLDER = 'dist';
const OUTPUT_SUFFIX = '.bundle.js';
const WEBPACK_HOT_POLL = 'webpack/hot/poll?1000';

module.exports = {
entry: {
[SERVER_ENTRY_NAME]: [
WEBPACK_HOT_POLL,
path.resolve(__dirname, '../../src/index.js'),
],
},
output: {
path: path.resolve(BUILD_FOLDER),
filename: `[name]${OUTPUT_SUFFIX}`,
},
watch: true,
target: 'node',
node: {
__filename: true,
__dirname: true,
},
externals: [
nodeExternals({
whitelist: [WEBPACK_HOT_POLL],
}),
],
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
],
},
plugins: [
new StartServerPlugin(SERVER_ENTRY_NAME + OUTPUT_SUFFIX),
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
'process.env': {
BUILD_TARGET: JSON.stringify('server'),
},
}),
],
};

最佳答案

可能这个地址正在使用:127.0.0.1:389,换个端口

关于mongodb - API 错误 : Error: connect ECONNREFUSED 127. 0.0.1:389 Apollo-React MongoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49010625/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com