0

我正在 Google Cloud App Engine 中使用 NodeJS 和 Fastify

我使用 ssh 连接到实例控制台我执行了“which openssl”,结果是“/usr/bin/openssl”所以我以这种方式配置了我的 server.js

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');
    });
};

我试图实现的功能是:

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));
  
  };

错误是:

你触发了一个 unhandledRejection,你可能忘记捕获一个 Promise 拒绝:

错误:在此路径上的系统上找不到 openssl:/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) 在 E (/usr/src/app/node_modules/which/which.js:80:29) 在 /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 id: 1)

我用来制作“gcloud app deploy”的 Dockerfile 是:

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"]

4

0 回答 0