我的服务器正在运行,但经过一段时间的工作后,它停止响应请求,继续尝试加载页面,让我无法建立连接。
我的app.js
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var oracledb = require('oracledb');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var multer = require('multer');
var fileUpload = require('express-fileupload');
var sessionStore;
var app = express();
var oracleDbStore = require('express-oracle-session')(session);
var connect = require(path.join(__dirname, 'connection', 'conn'))(2);
oracledb.createPool(connect, function(err, pool) {
if (err) {
console.error("createPool() error: " + err.message);
return;
}
pool.getConnection(function(err, connection) {
if (err) {
handleError(response, "getConnection() error", err);
return;
}
var diffopt = {externalAuth: true,
checkExpirationInterval: 900000,
expiration: 86400000,
createDatabaseTable: true,
connectionLimit: 1,
schema: {
tableName: 'sessions',
columnNames: {
session_id: 'session_id',
expires: 'expires',
data: 'data'
}
}};
var options = Object.assign({},connect,diffopt);
sessionStore = new oracleDbStore(options, connection);
});
});
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'twig');
// uncomment after placing your favicon in /public
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(fileUpload());
app.use(cookieParser());
app.use('/files',express.static(path.join(__dirname, 'public')));
app.use('/archivos',express.static(path.join(__dirname, 'archivos')));
app.set('trust proxy', 1);
app.use(session({
secret: "work",
name: 'sessionId',
store:sessionStore,
resave: false,
saveUninitialized: false
}));
var links = require('./links');
for(var i=0;i<links.length;i++){
app.use(links[i].route, require(links[i].direction));
}
app.get('*',function(req,res){
res.redirect('/');
});
app.get('/', function(req, res){
res.sendFile(path.join(__dirname, 'views/index.twig'));
});
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// 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;
停止响应但仍获得请求时记录服务器。它无法加载任何视图或静态文件。
GET /files/stylesheets/jquery-ui.css - - ms - -
GET /files/jscript/jquery.min.js - - ms - -
GET /files/stylesheets/font-awesome.min.css - - ms - -
GET /files/stylesheets/style.css - - ms - -
GET /files/stylesheets/AdminLTE.css - - ms - -
GET /files/stylesheets/bootstrap.min.css - - ms - -
GET / 304 2.676 ms - -
GET /files/stylesheets/AdminLTE.css - - ms - -
GET /files/stylesheets/style.css - - ms - -
GET /files/stylesheets/font-awesome.min.css - - ms - -
GET /files/stylesheets/bootstrap.min.css - - ms - -
GET /files/stylesheets/jquery-ui.css - - ms - -
GET / 304 2.759 ms - -
GET /files/stylesheets/jquery-ui.css - - ms - -
GET /files/jscript/jquery.min.js - - ms - -
GET /files/stylesheets/bootstrap.min.css - - ms - -
GET /files/stylesheets/font-awesome.min.css - - ms - -
GET /files/stylesheets/AdminLTE.css - - ms - -
GET /files/stylesheets/style.css - - ms - -
GET /login 200 1.157 ms - 1417
GET /files/imagenes/up.jpeg - - ms - -
GET /files/stylesheets/bootstrap.min.css - - ms - -
GET /files/stylesheets/bootstrap.min.css - - ms - -
POST /login - - ms - -
最后我需要重新启动服务器以使其再次运行。
答案 0 :(得分:0)
感谢您的回复,问题是oracledb池,当它到期时它会挂起服务器。我为express-file-store更改了它,现在它工作正常。
app.use(session({
store: new FileStore(options),
secret: "work",
name: 'sessionId',
resave: true,
saveUninitialized: false
}));