在nginx和pm2下运行的服务器。 它使用mongoose来连接到MongoDB Atlas。 前端使用axios从服务器获取数据。
服务器运行了很长时间(几天)后,我的网站无法从MongoDB Atlas获取数据。显示500个服务器错误。
服务器仍在运行,显示用户界面,但无法获取数据。重新启动整个服务器后,它就可以正常工作。
谁遇到过这种情况?
服务器
import * as React from 'react';
import {Suspense} from 'react';
import {View,Image,StyleSheet,Text,Button} from 'react-native';
import NavigationService from './NavigationService';
import MenuLogic from './LoadMenuLogic';
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
const TScreenReceive=({navigation})=>{
// const Y = "./"+navigation.getParam('userName');
const Comp = React.lazy( () => import('./Mosely'))
return (
<Suspense fallback={null}>
<Comp />
</Suspense>
);
}
const TScreen=()=>{
return(
<TScreenReceive />
)};
export {TScreen};
连接mongoDB
const express = require('express')
const connectDB = require('./config/db.js')
const cors = require('cors')
const path = require('path')
const app = express()
// Connect Database
connectDB()
// Init middleware
app.use(express.json())
app.use(cors())
// Define routes
app.use('/api/users', require('./routes/api/users'))
app.use('/api/auth', require('./routes/api/auth'))
app.use('/api/profile', require('./routes/api/profile'))
app.use('/api/posts', require('./routes/api/posts'))
// Serve the static assets in production
if (process.env.NODE_ENV === 'production') {
// Set static folder
app.use(express.static('client/build'))
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
})
}
const PORT = process.env.PORT || 5000
app.listen(PORT, () => console.log(`Server started on port ${PORT}`))