Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prep shared API URL util for use on external sites #6223

Merged
merged 1 commit into from
Dec 15, 2015

Conversation

ErisDS
Copy link
Member

@ErisDS ErisDS commented Dec 15, 2015

refs #5942, #6150

There were a few key problems I was looking to solve with this:

  • Introduce a single point of truth for what the URL for accessing the API should be
  • Provide a simple way to configure the utility (much like a true SDK)

As of this commit, this utility is still automatically available in a Ghost theme.
To use it on an external site, the code would look like:

<script type="text/javascript" src="http://my-ghost-blog.com/shared/ghost-url.min.js"></script>
<script type="text/javascript">
ghost.init({
   clientId: "<your-client-id>",
   clientSecret: "<your-client-secret>"
});
</script>

To achieve this, there have been a number of changes:

  • A new apiUrl function has been added to config, which calculates the correct URL. This needs to be unified with the other url generation functions as a separate piece of work.
  • The serveSharedFile middleware has been updated, so that it can serve files from / or /shared and to substitute {{api-url}} as it does {{blog-url}}.
  • ghost-url.js and ghost-url.min.js have been updated to be served via the serveSharedFile middleware
  • ghost-url.js has been changed slightly, to take the url from an inline variable which is substituted the first time it is served
  • {{ghost_head}} has been updated, removing the api url handling which is now in config/url.js and removing the configuration of the utility in favour of calling init() after the script is required
  • {{ghost_head}} has also had the meta tags for client id and secret removed
  • tests have been updated

@ErisDS ErisDS force-pushed the ghost-url branch 2 times, most recently from d300498 to 3d67387 Compare December 15, 2015 11:42
refs TryGhost#5942, TryGhost#6150

There were a few key problems I was looking to solve with this:

- Introduce a single point of truth for what the URL for accessing the API should be
- Provide a simple way to configure the utility (much like a true SDK)

As of this commit, this utility is still automatically available in a Ghost theme.
To use it on an external site, the code would look like:

```
<script type="text/javascript" src="http://my-ghost-blog.com/shared/ghost-url.min.js"></script>
<script type="text/javascript">
ghost.init({
   clientId: "<your-client-id>",
   clientSecret: "<your-client-secret>"
});
</script>
```

To achieve this, there have been a number of changes:

- A new `apiUrl` function has been added to config, which calculates the correct URL. This needs to be unified with the other url generation functions as a separate piece of work.
- The serveSharedFile middleware has been updated, so that it can serve files from / or /shared and to substitute `{{api-url}}` as it does `{{blog-url}}`.
- ghost-url.js and ghost-url.min.js have been updated to be served via the serveSharedFile middleware
- ghost-url.js has been changed slightly, to take the url from an inline variable which is substituted the first time it is served
- `{{ghost_head}}` has been updated, removing the api url handling which is now in config/url.js and removing the configuration of the utility in favour of calling `init()` after the script is required
- `{{ghost_head}}` has also had the meta tags for client id and secret removed
- tests have been updated
sebgie added a commit that referenced this pull request Dec 15, 2015
Prep shared API URL util for use on external sites
@sebgie sebgie merged commit efaa04b into TryGhost:master Dec 15, 2015
ErisDS added a commit to ErisDS/Ghost that referenced this pull request Dec 15, 2015
refs TryGhost#6223

- I made a stupid error, whereby apiUrl was always set to '' in themes
@ErisDS ErisDS deleted the ghost-url branch February 2, 2016 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants