@churchcenter/url
Church Center origin generator for JavaScript.
Builds runtime-environment-considered origins and urls in JavaScript for Church Center subdomains.
For those familiar with @planningcenter/url
, it may be worth noting that this generator has no concerns about what application is building the urls.
Examples
This package is primarily concerned with building origins and urls in the browser.
It is smart about inferring the Church Center origin from the current window.location.origin
.
If window.location.origin
is unavailable (like in the tests), an origin can be passed explicitly, but you'll most likely only need that for composing urls across subdomains.
import { buildSubdomain, buildUrl } from "@churchcenter/url"
let api = buildSubdomain("api")
let myGroupsUrl = buildUrl("/groups/profile")
Composition
Want to build API urls or app-specific urls?
Compose to your heart's content!
import { buildSubdomain, buildUrl } from "@churchcenter/url"
function bouldGroupsUrl(pathname) {
return buildUrl(`/groups${pathname}`)
}
let myGroupsUrl = buildGroupsUrl("/profile")
function buildApiUrl(pathname) {
return buildUrl(pathname, buildSubdomain("api"))
}
function buildPeopleApiUrl(pathname) {
return buildApiUrl(`/people/v2${pathname}`)
}
function buildFormUrl(id) {
return buildPeopleApiUrl(`/forms/${id}`)
}
let formUrl = buildFormUrl(42)
Installation
Script tag on Rails
<script type="javascript" src="https://unpkg.com/@churchcenter/url/dist/url.umd.js"></script>
Webpacker on Rails
yarn add @churchcenter/url
import { buildSubdomain, buildUrl } from "@churchcenter/url";