Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image emded url not pointing to Strapi Uploads URL in Next.js- Broken image links #62

Open
da-kicks-87 opened this issue May 3, 2023 · 2 comments

Comments

@da-kicks-87
Copy link

Hello,

When i upload an image from Strapi Media Libray and the view my Next.js front end, I see broken image links.
I check the link and it is going to to my Next.js url (http://localhost:3000) becasue of the relative path (/uploads/image-file_name_2133913322.png. My local Strapi env is at path http://localhost:1337.

How do I get it to work on my local env?

@0ndt
Copy link

0ndt commented May 23, 2023

You can use redirects in your next.config.js


/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  async redirects() {
    return [
      {
        source: '/uploads/:path*',
        destination: `http://localhost:1337/uploads/:path*`,
        permanent: true,
      },
    ]
  },
}
module.exports = nextConfig

@HackMEAny
Copy link

You can add the url parameter in Strapi "config\server.js"
url -> Backend Link

config\server.js

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337),
  url: 'http://127.0.0.1:1337',
  app: {
    keys: env.array('APP_KEYS'),
  },
  webhooks: {
    populateRelations: env.bool('WEBHOOKS_POPULATE_RELATIONS', false),
  },
});

After this you can access the Strapi admin panel from -> http://127.0.0.1:1337/admin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants