x-devapi无法连接到Google应用引擎中的数据库

时间:2018-07-01 20:50:50

标签: mysql node.js google-app-engine google-cloud-platform mysqljs

我正在将一个简单的nodejs服务器部署到App-engine,除了使用X-devapi进行数据库连接外,该服务器运行良好。我收到此错误:

All routers failed.

这是我使用的代码:

'use strict';

const express = require('express');
const mysqlx = require('@mysql/xdevapi');

const app = express();
app.get('/', (req, res) => {
  const options = { user: 'user_name', password: '@pass',host: 'XX.XXX.XX.XXX'
/*Here I used Public IP address on the of the SQL instance*/,port: XXXX
/*I assigned port 8080 here*/, schema: 'db_name' };

(async function () {
  let session;

  try {
    session = await mysqlx.getSession(options);

    const collection = await session.getSchema(options.schema).createCollection('collection');
    await collection.add({ name: 'foo' }).execute();
    await collection.find().fields('name').execute(console.log); // { name: 'foo' }
  } catch (err) {
    //console.error(err.message);
    res.status(200).send(err.message).end();//used code 200 in order to receive the error too
  } finally {
    session && session.close();
  }
})();
});

// Start the server
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
  console.log(`App listening on port ${PORT}`);
  console.log('Press Ctrl+C to quit.');
});

我该如何解决?

1 个答案:

答案 0 :(得分:1)

事实证明,如果您检查对我的担忧here和功能请求here的响应,则Google Cloud SQL工具仍未启用X devAPI