Проблема с подключением к MongoDB Atlas из приложения Docker, размещенного на платформе Google - PullRequest
0 голосов
/ 07 марта 2020

проблема:

Это то, что происходит, когда я сверну конечную точку http://ip/getuser/

UnhandledPromiseRejectionWarning: MongoParseError: URI malformed, cannot be parsed
at parseConnectionString (/app/node_modules/mongodb/lib/core/uri_parser.js:542:21)
at connect (/app/node_modules/mongodb/lib/operations/connect.js:272:3)
at cb (/app/node_modules/mongodb/lib/mongo_client.js:221:5)
at maybePromise (/app/node_modules/mongodb/lib/utils.js:714:3)
at MongoClient.connect (/app/node_modules/mongodb/lib/mongo_client.js:217:10)
at Function.MongoClient.connect (/app/node_modules/mongodb/lib/mongo_client.js:427:22)
at exports.IsCardActivated (/app/routes/index.js:47:45)
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
at next (/app/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing in
side of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (re
jection id: 2)
(node:1) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejectio
ns that are not handled will terminate the Node.js process with a non-zero exit code.

router / getuserbydetails

const MongoClient = require('mongodb').MongoClient;
require('dotenv').config()

function connectUrl() {
  return process.env.url;
}


exports.GetUserDetails = async (req, res) => {
....

    if (!client) client = await MongoClient.connect(connectUrl(), { useNewUrlParser: true })
    const db = client.db(getDatabaseName());

  ....

};

./index.js

var user= require('./routes/user/index');
app.get('/getuser', user.getuser);

Dockerfile

FROM node:10
ENV NODE_ENV="production"

COPY . /app
WORKDIR /app
RUN npm install

ENV PORT 80
EXPOSE 80
CMD [ "node", "index.js" ]

Платформа Google: настройка экземпляра GCE:

This is a picture of the Instance Setting I am using. I have the https enabled but the Http setting disabled, The instance type is N1 as standard and I have made the instance containerized optimized OS- which is provided by Google, I've allowed default access, network settings is being handled by a load balancer and firewall Примечание :

брандмауэр : разрешить 443, 80

с использованием LB на передней панели приложения.

Это приложение отлично работает локально Мне интересно, где это может пойти не так.

...