connect-history-api-fallback get无法访问

时间:2019-03-21 04:17:27

标签: express

在设置nodejs(作为后端,端口:3333)和vuejs(前端,端口:8080)环境期间,我无法访问“ GET / article”。另外,当我删除connect-history-api-fallback时,我只能看到json格式的数据库数据。

我该如何解决?

下面是app.js的代码:

var express = require('express');
var app = express();
var history = require('connect-history-api-fallback');

app.use(history({
  index: '/index.html',
  verbose: true
}));
app.use(express.static(path.join(__dirname, 'public')));
// app.use(bodyParser.json());

var IndexRouter = require('./routes/index');
var ArticleRouter = require('./routes/article');

app.use('/', IndexRouter);
app.use('/article', ArticleRouter);

以下是route / article.js的代码:

var express = require('express');
var router = express.Router();
var mysql = require('mysql');

router.get('/', function (req, res) {
    console.log('article get 접근하였습니다.');
    pool.getConnection(function (err, connection) {
        if (err) {
            throw error;
        }
        const sqlQuery = 'SELECT * from board_article';
        connection.query(sqlQuery, function (err, rows) {

            if (err) {
                connection.release();
                throw error;
            } else {
                res.json(rows);
                connection.release();
            }
        });
    });
});

0 个答案:

没有答案