strapi-plugin-ckeditor icon indicating copy to clipboard operation
strapi-plugin-ckeditor copied to clipboard

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

Open da-kicks-87 opened this issue 2 years ago • 2 comments

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?

da-kicks-87 avatar May 03 '23 19:05 da-kicks-87

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

0ndt avatar May 23 '23 09:05 0ndt

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

HackMEAny avatar Jun 30 '23 15:06 HackMEAny