首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >tedious4快递永不返回响应

tedious4快递永不返回响应
EN

Stack Overflow用户
提问于 2022-04-04 14:23:55
回答 1查看 88关注 0票数 0

我正在使用express4 4乏味的方法来构建一个SQL

这是我的密码

代码语言:javascript
复制
const express = require('express');     // OAuth2 needs a web server to call back to
const morgan = require('morgan');       // morgan is HTTP middleware and logging
const path = require('path');           // helps resolving file paths
const fs = require('fs');               // filesystem
// https://www.npmjs.com/package/express4-tedious
const tediousExpress = require('express4-tedious');

dbconfig=
{
    "server"  : "localhost",
    "userName": "uname",
    "password": "pwd",
    "options": { "encrypt": true, "database": "MyDB", "trustServerCertificate":false }
}



const app = express();

// add tediousExpress to the middleware chain
app.use(function (req, res, next) {
    req.sql = tediousExpress(dbconfig);
    next();
});

// Initialize variables.
const port = 3030;

// Configure morgan module to log all requests.
app.use(morgan('dev'));

/* commented out to simplify issue
// set up route for static files
app.use(express.static('webapp/static'));
app.use(express.static('webapp/js'));
app.use(express.static('webapp/library'));
*/

// Start the server.
app.listen(port);
console.log('Listening on port ' + port + '...');

// Set up a route for index.html.
app.get('/', function(req, res) {
    res.sendFile(path.join(__dirname + '/webapp/index.html'));
});

app.get('/sm', function (req, res) {
    
    console.log("handling system")

    res.setHeader("Content-Type", "application/json");
 
    req
    .sql("select * from Mytable for json path")
    .fail(function(ex, res) { 
        res.statusCode = 500;   
        res.write(ex.message);
        res.end();
    } )    
    .into(res, '{}');

    // This always shows [] 
    console.log(res.outputData);
    
    // B. If I don't put this line in, the web page gets stuck
    res.send(res.outputData);


});

我正在用VS代码来运行这个。控制台在我点击URL时显示了这一点

代码语言:javascript
复制
handling system
[]

代码注释中提到了我的问题。

问题A

res.outputData总是显示[],即使我知道查询返回JSON。

问题B

如果我不把res.send(res.outputData);放在代码中,当我调用url时

  • 网页只会永远旋转
  • 我可以在chrome网络监视器中看到我的url没有响应。

另外,

  • 显式发送res.outputData数据作为参数似乎是多余的。
  • 这段代码是我从实验中得到的。
  • 下面的链接中的示例代码没有一个需要额外的行。

堆栈过流

github

我对node.js还不太熟悉,无法解决问题。我觉得模块里可能有什么不对劲的地方,没有给我看。

当我在VS代码中执行和调试时,我可以看到一个关于未找到的页面的错误,但是我认为这可能是一个红色的鲱鱼。

正如我所了解的,这个代码是80%的剪切‘n’粘贴。

如果有一个比express4-tedious更可靠的SQL库,我很乐意接受建议。

这里有示例代码https://github.com/JocaPC/express4-tedious

编辑:

  • 我添加了一个.fail函数,但是结果没有变化。
  • 我在里面放了一个无稽之谈的服务器名,它的行为也是一样的。所以它似乎失败了,但没有引起任何错误,也没有给出任何线索
EN

回答 1

Stack Overflow用户

发布于 2022-06-28 20:07:38

你的

代码语言:javascript
复制
dbconfig=
{
    "server"  : "localhost",
    "userName": "uname",
    "password": "pwd",
    "options": { "encrypt": true, "database": "MyDB", "trustServerCertificate":false }
}

be

代码语言:javascript
复制
dbconfig=
{
    server  : "localhost",
    userName: "uname",
    password: "pwd",
    options: { encrypt: true, database: "MyDB", trustServerCertificate:false }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71738926

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档