diff options
Diffstat (limited to 'src/Image.tsx')
-rw-r--r-- | src/Image.tsx | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/Image.tsx b/src/Image.tsx new file mode 100644 index 0000000..770c383 --- /dev/null +++ b/src/Image.tsx @@ -0,0 +1,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; |