http
Download and add registry items from an arbitrary HTTP endpoint.
The http provider is the simplest provider by far. To add registry items simply provide the base url of the registry.json file:
jsrepo add https://example.com/registryjsrepo will then find the registry.json file from https://example.com/registry/registry.json.
Deploying a registry to your own website
When deploying a registry to your own website you will want to use the distributed output type:
import { defineConfig } from "jsrepo";
import { distributed } from "jsrepo/outputs";
export default defineConfig({
// `dir` is the directory to output the files to
outputs: [distributed({ dir: "./public/r" })],
});This will output your registry to the public/r directory which might look something like this:
Users will then be able to add registry items to their project by running:
jsrepo add https://your-website.com/rAuthentication
To authenticate with the http provider you can run the following command:
jsrepo auth httpYou will then be prompted to select or enter the name of a registry to authenticate to.
Once authenticated that token will continue to be used for that registry until you logout.
You can logout of your account by running:
jsrepo auth http --logoutOptions
baseUrl
The baseUrl option allows you to configure what registries this provider will match.
import { defineConfig } from "jsrepo";
import { http } from "jsrepo/providers";
export default defineConfig({
// only use this provider for registries starting with https://myregistry.com
providers: [
http({
baseUrl: "https://myregistry.com"
})
],
});authHeader
The authHeader function allows you to set headers for every request using the provided token. This is useful for when you need to authenticate to a registry that doesn't support the Bearer token format.
import { defineConfig } from "jsrepo";
import { http } from "jsrepo/providers";
export default defineConfig({
providers: [
http({
// set your custom headers here
authHeader: (token) => ({ 'X-API-Key': token })
})
],
});headers
You can set custom headers on every request by providing the headers option:
import { defineConfig } from "jsrepo";
import { http } from "jsrepo/providers";
export default defineConfig({
providers: [
http({
headers: {
'X-Custom-Header': 'custom value'
}
})
],
});One way you might use headers is by providing an authorization token via an environment variable:
import { defineConfig } from "jsrepo";
import { http } from "jsrepo/providers";
export default defineConfig({
providers: [
http({
baseUrl: "https://myregistry.com",
headers: {
Authorization: `Bearer ${process.env.MYREGISTRY_TOKEN}`
}
})
],
});Now anyone running jsrepo add will have the Authorization header set to the value of the MYREGISTRY_TOKEN environment variable when making requests to https://myregistry.com/registry.