I've had a problem with Nuxt3 for some time, or more precisely with Nitro built into it. I'm using the experimental "database" option and I'm using mysql2 as a connector. The problem is that after some time of inactivity on the site, it disconnects the connection to the database and the only thing I have in the logs is this:
[nuxt] [request error] [unhandled] [500] Can't add new command when connection is in closed state
This is what my nuxt.config.ts file looks like:
import { fileURLToPath } from 'url';
import { dirname, resolve } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export default defineNuxtConfig({
css: [
'@/assets/css/custom-scrollbar.css'
],
ssr: true,
app: {
baseURL: "/",
},
compatibilityDate: "2024-11-01",
devtools: { enabled: true },
modules: [
"@nuxtjs/tailwindcss",
"nuxt-auth-utils",
"@nuxt/image",
"@nuxt/icon"
],
nitro: {
experimental: {
database: true
},
database: {
default: {
connector: 'mysql2',
options: {
database: process.env.NUXT_MYSQL_DATABASE_NAME,
user: process.env.NUXT_MYSQL_USER,
password: process.env.NUXT_MYSQL_PASSWORD,
host: process.env.NUXT_MYSQL_HOST,
port: process.env.NUXT_MYSQL_PORT,
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0,
enableKeepAlive: true,
}
}
},
storage: {
db: {
driver: 'fs',
base: resolve(__dirname, '.cache/db')
}
}
}
});