aboutsummaryrefslogtreecommitdiff
path: root/src/Image.tsx
blob: 770c3832816d807318a40064538c224f30926129 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import ImageBase from 'next/future/image';
import { FC } from 'react';

type Props = Record<'src' | 'alt', string>;

const IMAGE_CDN = 'http://localhost:8000';

const localizeSrc = (src: string) => {
  if (process.env.NODE_ENV === 'production' || src.startsWith('http')) return src;
  return IMAGE_CDN + src;
}

const Image: FC<Props> = ({ src, ...props }) => {
  const source = localizeSrc(src);

  return (
    <ImageBase src={source} {...props} />
  )
}

export default Image;