V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
declandragon
V2EX  ›  前端开发

VUE2 nuxt2 windows docker 启动 ctx.$axios.get 访问多语言文件 404 问题

  •  
  •   declandragon · 2 天前 · 144 次点击

    环境相关

    • win 10 专业版
    • Docker Desktop 4.37.1 (178610) 最新版

    package.json

      "scripts": {
        "dev": "cross-env ENV=company NODE_ENV=development LOCATION=pre nodemon server/index.js --watch server",
        "dev_online": "cross-env ENV=online NODE_ENV=development nodemon server/index.js
      },
    
      "dependencies": {
        "@elk/analytics": "^2.2.3",
        "@nuxtjs/axios": "^5.11.0",
        "@nuxtjs/style-resources": "^1.0.0",
        "@sentry/tracing": "^7.98.0",
        "@sentry/vue": "^7.98.0",
        "@utils/elk-common": "^1.0.0",
        "access-log": "^0.4.1",
        "clipboard": "^2.0.11",
        "cookie-universal-nuxt": "^2.1.3",
        "cross-env": "^5.2.0",
        "express": "^4.16.4",
        "js-base64": "^2.6.3",
        "node-libcurl": "^3.0.0",
        "nuxt": "^2.12.0",
        "nuxt-start": "^2.12.2",
        "velocity-animate": "^1.5.2",
        "vue-i18n": "^8.15.3",
        "vue-lazyload": "^1.3.3",
        "vue-recaptcha": "^1.3.0"
      }
    

    docker-compose.yml

    version: '3'
    services:
      my_xxxx_node_14:
        container_name: my_xxxx_node_14
        image: node:14
        ports:
          - "3014:3000"
        volumes:
          - ../:/app
        working_dir: /app
        command: sh -c "npm install -g nodemon && npm run dev"
        networks:
          - frontend
    
    networks:
      frontend:
        external: true
    

    关键代码

    // process.browser = false ,确定代码是在服务端执行的
    const host = !process.browser
     ? 'http://127.0.0.1:3000'
     : `${ctx.protocol}//${ctx.host}`
    const request_url = `${host}${langDir}/${ctx.store.state.locale}/${file}.json`
    
    ctx.$axios.get(request_url)
    
    

    问题描述

    docker compose up -d 启动项目后,http://127.0.0.1:3014 项目可以正常访问

    请问这是什么原因?

    尝试使用 curl 请求,带来了新的问题解决不了

    安装这个包之后,项目启动访问 http://localhost:3014/blog/ 会报错,npm 卸载重装,删除容器重启都没用,

    in ./node_modules/node-libcurl/lib/binding/node_libcurl.node 1:2
    Module parse failed: Unexpected character '�' (1:2)
    You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
    (Source code omitted for this binary file)
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1029 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 19ms · UTC 20:17 · PVG 04:17 · LAX 12:17 · JFK 15:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.