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

3 天前
 declandragon

环境相关

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)
155 次点击
所在节点    前端开发
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1102837

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX