const { defineConfig } = require('@vue/cli-service')

module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave: false,
  devServer: {
    port: 8080,
    host: '0.0.0.0',
    historyApiFallback: true,
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:5000',
        changeOrigin: true,
        ws: false,
        logLevel: 'debug',
        onError(err, req, res) {
          console.error('[proxy error]', req && req.url, err && err.message)
          if (res && !res.headersSent) {
            res.writeHead(502, { 'Content-Type': 'application/json; charset=utf-8' })
            res.end(JSON.stringify({ code: -1, message: '后端代理失败，请确认 Flask 已在 5000 端口运行：' + (err && err.message) }))
          }
        }
      }
    }
  }
})
