# astro-https-image-endpoint

> As an alternative image endpoint in Astro local development

Latest version **0.1.1** (published 2023-09-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install astro-https-image-endpoint
pnpm add astro-https-image-endpoint
yarn add astro-https-image-endpoint
bun add astro-https-image-endpoint
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2023-09-27 |
| First published | 2023-09-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.14.1 |
| Dependencies | 1 |
| Unpacked size | 7.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 0 |
| Author | @unix |
| Maintainers | echo_unix |
| Keywords | astro, https, image, endpoint |

## Links

- npm: https://www.npmjs.com/package/astro-https-image-endpoint
- Repository: https://github.com/unix/astro-https-image-endpoint
- Homepage: https://github.com/unix/astro-https-image-endpoint#readme
- Issues: https://github.com/unix/astro-https-image-endpoint/issues
- npm.io page: https://npm.io/package/astro-https-image-endpoint

## Dependencies (1)

- [mime](https://npm.io/package/mime.md) ^3.0.0

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 0.1.1 (latest) — 2023-09-27
- 1.0.0 — 2023-09-26
- 0.1.0 — 2023-09-26
- 0.0.7 — 2023-09-26
- 0.0.6 — 2023-09-26
- 0.0.5 — 2023-09-26
- 0.0.4 — 2023-09-26
- 0.0.3 — 2023-09-26
- 0.0.2 — 2023-09-26
- 0.0.1 — 2023-09-26

## README

## astro-https-image-endpoint

### Why

Astro's [image optimization service](https://docs.astro.build/en/guides/images/#images-in-astro-files) will not work when TLS enabled on localhost,
This issue has been on the back burner for a while,
but there is no consistent official solution, and the current issue is [low priority](https://github.com/withastro/astro/issues/8395) (and probably won't be fixed for some time).

It's a simple tool to help you take a break from TLS + Astro Image.

### Usage

- Install: `npm i astro-https-image-endpoint -D`
- Add to your `astro.config.mjs`:

```js
import { defineConfig } from 'astro/config'
import imageEndpoint from 'astro-https-image-endpoint'

export default defineConfig({
  image: {
    // Pass "import.meta.env.DEV" to ensure it is only enabled on development.
    endpoint: imageEndpoint(import.meta.env.DEV),
  },
})
```

### Effects

- _**Production safe**_: Only be loaded in development mode;
- _**Performance safe**_: Only the read files (stay compatible with the original API);
- _**No caches**_: Usually, this will reduce your burden and do not require debugging due to issues with caching;

> If your site really does have 1k+ images on one page that load slowly due to disk I/O during development,
> then that's not relevant to this plugin and you may need a CDN or other cloud service.

### How to set HTTPS in Astro

This has nothing to do with this plugin.
But if you haven't started for Astro to enable TLS for local development, here's the reference configuration:

```ts
import { defineConfig } from 'astro/config'
import mkcert from 'vite-plugin-mkcert'
import imageEndpoint from 'astro-https-image-endpoint'

export default defineConfig({
  server: {
    host: 'my-domain.com',
    port: 3000,
  },
  image: {
    endpoint: imageEndpoint(import.meta.env.DEV),
  },
  vite: {
    plugins: [mkcert({ hosts: ['my-domain.com'] })],
  },
})
```

### License

[MIT](LICENSE)

---
_Source: https://npm.io/package/astro-https-image-endpoint · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
