0

I'm working with NodeJS and Fastify in Google Cloud App Engine

I connected to the console of instances with ssh I executed "which openssl" and the result was "/usr/bin/openssl" so I configured my server.js in this way

const pem = require('pem');
const jwt = require('fastify-jwt');
const multipart = require('fastify-multipart');
const cors = require('fastify-cors');

const createServer = (options) => {

    const { logSeverity } = options;
    const server = fastify({
        ignoreTrailingSlash: true,
        logger: {
            level: logSeverity
        }
    });
    pem.config({
        pathOpenSSL: '/usr/bin/openssl'
    }); 

    ...

    server.listen(8080, '0.0.0.0', (err) => {
        if (err) {
            server.log.error(err);
            console.log(err);
            process.exit(1);
        }
        server.log.info('Server Started');
    });
};

the function that Im trying to implement is:

const WebPay = require('webpay-nodejs');;

let wp = new WebPay({
    commerceCode: cert.commerceCode,
    publicKey: cert.publicKey,
    privateKey: cert.privateKey,
    webpayKey: cert.webpayKey,
    verbose: true,
    env: WebPay.ENV.INTEGRACION
  });

  const pay = async (req, res) => {

    let buyOrden = Date.now();
    //transactions[buyOrden] = { amount: amount};
    let url = 'xxxxx';

    await wp.initTransaction({
      buyOrder: buyOrden,
      sessionId: req.body.sessionId,
      returnURL: url + '/verify',
      finalURL: url + '/voucher',
      amount: 10000
    }).then((data) => {
        return res.send(data.url + '?token_ws=' + data.token);
    }).catch(onError(res));
  
  };

and the error is:

You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:

Error: Could not find openssl on your system on this path: /usr/bin/openssl at /usr/src/app/node_modules/pem/lib/openssl.js:237:23 at F (/usr/src/app/node_modules/which/which.js:68:16) at E (/usr/src/app/node_modules/which/which.js:80:29) at /usr/src/app/node_modules/which/which.js:89:16 at /usr/src/app/node_modules/isexe/index.js:42:5 at /usr/src/app/node_modules/isexe/mode.js:8:5 at FSReqWrap.oncomplete (fs.js:153:21)

(node:17) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1)

the Dockerfile that I use to make "gcloud app deploy" is:

FROM keymetrics/pm2:10-alpine
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY ["package.json","package-lock.json","/usr/src/app/"]
RUN apk add --no-cache --virtual .gyp \
        python \
        make \
        g++ \
    && npm install -g node-gyp \
    && npm install --only=production \
    && apk del .gyp
COPY [".","/usr/src/app/"]
EXPOSE 8080
CMD ["pm2-runtime","start","ecosystem.config.js","--env","production"]

0 Answers0