本文介绍了x-devapi无法连接到Google App Engine中的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在向App引擎部署一个简单的nodejs
服务器,该服务器运行良好,除了使用X-devapi
进行数据库连接之外.我收到此错误:
I am deploying a simple nodejs
server to App-engine which works well except for the database connection using the X-devapi
. I am getting this error:
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.');
});
我该如何解决?
推荐答案
事实证明,如果您检查对我所关注问题的答复,则Google Cloud SQL工具仍未启用X devAPI
. stackoverflow.com/a/51212131/8098918>此处和功能请求此处
It turns out that Google cloud SQL tools still do not have the X devAPI
enabled if you check response to my concern here and the feature request here
这篇关于x-devapi无法连接到Google App Engine中的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!