最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - Nuxt3 Nitro keeps disconnecting mysql connection - Stack Overflow

programmeradmin2浏览0评论

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')
      }
    }
  }
});
发布评论

评论列表(0)

  1. 暂无评论