bridge icon indicating copy to clipboard operation
bridge copied to clipboard

Nuxt Bridge app.baseURL doesn't work with i18n module

Open thomas4Bitcraft opened this issue 3 years ago • 9 comments

Environment


  • Operating System: Darwin
  • Node Version: v14.18.1
  • Nuxt Version: latest
  • Package Manager: [email protected]
  • Bundler: Webpack
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

nuxt.config.js

import { defineNuxtConfig } from '@nuxt/bridge'

export default defineNuxtConfig({
router: {
    base: '/d/'
  },
})

Describe the bug

The base path in nuxt bridge seems to be broken. If I set it to the above /d/ every preload link in the frontend is set to /d/d/ and all files are also reachable only with this path.

image image

It seems the only url which is not affected by this is the one to the header js file in production image

What makes the thing worse - because the file lies under /d/d/ and the whole site is broken

Additional context

No response

Logs

No response

thomas4Bitcraft avatar Feb 17 '22 22:02 thomas4Bitcraft

@danielroe I made a mistake at my initial issue: /d is also not working. So the basePath property as a whole seems to be broken right now

thomas4Bitcraft avatar Feb 17 '22 22:02 thomas4Bitcraft

To configure the base path with Nitro, don't configure router.base directly. Instead, you can pass NUXT_APP_BASE_URL or set app.baseURL.

For example:

yarn build
NUXT_APP_BASE_URL=/d node .output/server/index.mjs

Or:

  import { defineNuxtConfig } from '@nuxt/bridge'
  
  export default defineNuxtConfig({
-   router: {
-     base: '/d/'
-   },
+   app: {
+     baseURL: '/d/'
+   },
  })

Let me know if that resolves it for you.

danielroe avatar Feb 17 '22 22:02 danielroe

@danielroe The assets are now resolved and are reachable under /d/. The problem now are the pages or precisely the i18n package.

We have a Cloudfront which routes all /d/ traffic to the lambda where the nuxt application is loaded. But without the router option <domain>/d/en/login is redirected to <domain>/en/login and therefore outside of the application.

thomas4Bitcraft avatar Feb 17 '22 23:02 thomas4Bitcraft

The router option should be set dynamically based on the basePath. Perhaps you could share some reproduction code? 🙏

danielroe avatar Feb 17 '22 23:02 danielroe

Sure I'll create a reproduction. Another thing I noticed:

image The JS Files in `head` still seems to behave different than all the other nuxt files

thomas4Bitcraft avatar Feb 17 '22 23:02 thomas4Bitcraft

Would you open an issue on https://github.com/nuxt-community/i18n-module? 🙏

danielroe avatar Mar 01 '22 09:03 danielroe

The value of app.baseURL does not apply to ~static, while router.base does.

We were using ~static in img src attribute, e.g. . It works fine during local development, but when we start nuxi build we have to switch from router.base to app.baseURL, which fixes the preload link issue, but created ~static issue again.

For now we have to abandon ~static and replace it with the global var baseURL, not quite elegant anyway.

hughlv avatar Mar 28 '22 15:03 hughlv

I have the exact same issue with a nuxt/bridge even without using any third-party modules. When I define router.base with some value - let's assume /test/ for example - it gets doubled in the script routes embedded to the header. Any solution for this yet?

Снимок экрана 2022-08-12 в 17 34 44

sweetpalma avatar Aug 12 '22 14:08 sweetpalma

I was able to hard code _nuxt folder path using buildAssetsDir (it's not even documented!) - but I guess that's a pretty weak solution. Hope this issue will get addressed soon.

Снимок экрана 2022-08-15 в 23 53 50

sweetpalma avatar Aug 15 '22 20:08 sweetpalma

Same issue here.

emretepedev avatar Dec 18 '22 17:12 emretepedev

yes - also had the problem that my fonts in /assets were not found - because the prefix was missing - the key was to specify the buildAssetsDir string as specified by @sweetpalma even though it should be the default anyway...(i also added baseURL and router.base but buildAssetsDir really made all the difference)

app: {
  buildAssetsDir: '/_nuxt/'
}

saraha33 avatar Jan 26 '23 21:01 saraha33

I also had the same issue. I followed the work around by @sweetpalma and @saraha33. That fixed the issue. Thanks! At least buildAssetsDir is now in the docs.

ldavisCEI avatar Apr 20 '23 17:04 ldavisCEI