2.0.1 • Published 6 years ago

pco-url v2.0.1

Weekly downloads
332
License
MIT
Repository
github
Last release
6 years ago

DEPRECATED:

USE ORG-SCOPED @planningcenter/url

pco-url

A dumb url origin generator in JS.

Builds environment-considered url origins in JS-land, for Planning Center apps.

Examples

pcoUrl("development")("api")
// => "http://api.pco.test"

pcoUrl("staging")("people")
// => "https://accounts.planningcenteronline.com"

pcoUrl("production")("accounts")
// => "https://people-staging.planningcenteronline.com"

Arguments are curried. You can make a generic env-considered function.

const envPcoUrl = pcoUrl(window.railsEnv)
envPcoUrl("api")

In Planning Center Apps

Planning center apps expose the Rails env as the JS global railsEnv. Use like so.

pcoUrl(railsEnv)("api")

Fetching example

fetch(`${pcoEnvUrl(env)("api")}/people/v2/me`, {
  credentials: "include",
})
  .then(res => res.json())
  .then(json => json.data)
  .then(({ id, attributes }) =>
    this.setState({
      currentUser: {
        id,
        ...attributes,
      },
    })
  )
  .catch(err => console.log(err));

Installation

Script tag on Rails

<script type="javascript" src="https://unpkg.com/pco-url@1.0.0/lib/pco-url.js"></script>
<!-- exposed as global `pcoUrl` -->

Webpacker on Rails

yarn add pco-url
/* global railsEnv */
import pcoUrl from "pco-url"

pcoUrl(railsEnv)("api")
2.0.1

6 years ago

2.0.0

6 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago