gpt4 book ai didi

mysql - 使用 NodeJS 刷新 MySQL 查询页面时出现 404

转载 作者:行者123 更新时间:2023-11-30 21:27:01 25 4
gpt4 key购买 nike

所以我有一个快速运行的网站,使用一些 MySQL 查询来加载相册。问题是,当我转到/photo 时,一切正常,但如果我刷新页面,则会收到 404 NOT FOUND。如果我先访问/photo,然后访问另一个 url,然后返回/photo,情况也是一样。无论是在生产环境还是开发环境中,问题都会发生,但只发生在我的服务器上,从不发生在本地。

这是我得到的:

NotFoundError: Not Found
at /home/vincdgfq/sachalebas/app.js:53:7
at Layer.handle [as handle_request] (/home/vincdgfq/nodevenv/sachalebas/9/lib/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/home/vincdgfq/nodevenv/sachalebas/9/lib/node_modules/express/lib/router/index.js:317:13)
at /home/vincdgfq/nodevenv/sachalebas/9/lib/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/home/vincdgfq/nodevenv/sachalebas/9/lib/node_modules/express/lib/router/index.js:335:12)
at next (/home/vincdgfq/nodevenv/sachalebas/9/lib/node_modules/express/lib/router/index.js:275:10)
at /home/vincdgfq/nodevenv/sachalebas/9/lib/node_modules/express/lib/router/index.js:635:15
at next (/home/vincdgfq/nodevenv/sachalebas/9/lib/node_modules/express/lib/router/index.js:260:14)
at Function.handle (/home/vincdgfq/nodevenv/sachalebas/9/lib/node_modules/express/lib/router/index.js:174:3)
at router (/home/vincdgfq/nodevenv/sachalebas/9/lib/node_modules/express/lib/router/index.js:47:12)

如果我删除所有错误处理程序,我只会得到一个

CANNOT GET /501.shtml

网站可以在这里找到:https://sachalebas.com/photo

如果有人知道我应该在哪里寻找这个错误,我完全迷路了,在此先感谢您。

编辑:

var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var bodyParser = require('body-parser');
var session = require('express-session');

require('./controllers/userController');

const oneYear = 60 * 1000 * 60 * 24 * 7;
const xssFilter = require('x-xss-protection');
const noSniff = require('dont-sniff-mimetype');
require('dotenv').config({ path:"process.env"});
const compression = require('compression');
var indexRouter = require('./routes/index');



var app = express();
app.use(xssFilter());
app.use(noSniff());
app.use(compression());
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(express.static(__dirname + '/public', {maxAge: oneYear, dotfiles:'allow'}));
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({
extended: false
}));
app.use(cookieParser());

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));

app.use(session({
secret: process.env.SECRET,
resave: false,
saveUninitialized: false,
maxAge: 200000
}));



app.use('/', indexRouter);

// catch 404 and forward to error handler
app.use(function (req, res, next) {
next(createError(404));
});

// error handler
app.use(function (err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
});



module.exports = app;

这是我的 app.js

最佳答案

您的问题与后端无关。

我已经多次执行 curl 请求并且得到相同的输出: curl output

这意味着客户端出现竞争条件问题。

为了避免它尝试包装所有代码:https://sachalebas.com/ressources/js/script.js

内部:

window.onload = function() {
// here goes all js code from ressources/js/script.js
}

或者确保在图像之前渲染的 css 中没有阻塞层。

关于mysql - 使用 NodeJS 刷新 MySQL 查询页面时出现 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58411127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com