2017-11-02 23:35:58 +03:00
|
|
|
// Contains all path information to be used throughout the codebase.
|
|
|
|
// Assumes that config.url is set, and is valid
|
2017-12-15 00:32:34 +03:00
|
|
|
const moment = require('moment-timezone'),
|
2017-12-11 21:14:05 +03:00
|
|
|
_ = require('lodash'),
|
|
|
|
url = require('url'),
|
2017-12-15 00:32:34 +03:00
|
|
|
cheerio = require('cheerio'),
|
2017-12-14 05:01:23 +03:00
|
|
|
config = require('../../config'),
|
|
|
|
settingsCache = require('../settings/cache'),
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
// @TODO: unify this with the path in server/app.js
|
2017-12-11 21:14:05 +03:00
|
|
|
API_PATH = '/ghost/api/v0.1/',
|
2017-02-03 17:42:05 +03:00
|
|
|
STATIC_IMAGE_URL_PREFIX = 'content/images';
|
2014-01-05 10:40:53 +04:00
|
|
|
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
/**
|
|
|
|
* Returns the base URL of the blog as set in the config.
|
|
|
|
*
|
|
|
|
* Secure:
|
|
|
|
* If the request is secure, we want to force returning the blog url as https.
|
|
|
|
* Imagine Ghost runs with http, but nginx allows SSL connections.
|
|
|
|
*
|
2017-01-23 11:22:37 +03:00
|
|
|
* @param {boolean} secure
|
|
|
|
* @return {string} URL returns the url as defined in config, but always with a trailing `/`
|
|
|
|
*/
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
function getBlogUrl(secure) {
|
|
|
|
var blogUrl;
|
2017-01-23 11:22:37 +03:00
|
|
|
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
if (secure) {
|
|
|
|
blogUrl = config.get('url').replace('http://', 'https://');
|
2016-01-05 21:04:39 +03:00
|
|
|
} else {
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
blogUrl = config.get('url');
|
2016-01-05 21:04:39 +03:00
|
|
|
}
|
2017-01-23 11:22:37 +03:00
|
|
|
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
if (!blogUrl.match(/\/$/)) {
|
|
|
|
blogUrl += '/';
|
2017-01-23 11:22:37 +03:00
|
|
|
}
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
|
|
|
|
return blogUrl;
|
2015-04-10 18:59:38 +03:00
|
|
|
}
|
|
|
|
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
/**
|
2017-01-23 11:22:37 +03:00
|
|
|
* Returns a subdirectory URL, if defined so in the config.
|
|
|
|
* @return {string} URL a subdirectory if configured.
|
|
|
|
*/
|
2016-09-12 14:53:04 +03:00
|
|
|
function getSubdir() {
|
|
|
|
// Parse local path location
|
2017-11-02 23:35:58 +03:00
|
|
|
var localPath = url.parse(config.get('url')).path,
|
|
|
|
subdir;
|
2016-09-12 14:53:04 +03:00
|
|
|
|
2017-11-02 23:35:58 +03:00
|
|
|
// Remove trailing slash
|
|
|
|
if (localPath !== '/') {
|
|
|
|
localPath = localPath.replace(/\/$/, '');
|
2016-09-12 14:53:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
subdir = localPath === '/' ? '' : localPath;
|
|
|
|
return subdir;
|
|
|
|
}
|
|
|
|
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
function deduplicateSubDir(url) {
|
|
|
|
var subDir = getSubdir(),
|
|
|
|
subDirRegex;
|
|
|
|
|
|
|
|
if (!subDir) {
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
subDir = subDir.replace(/^\/|\/+$/, '');
|
|
|
|
subDirRegex = new RegExp(subDir + '\/' + subDir + '\/');
|
|
|
|
|
|
|
|
return url.replace(subDirRegex, subDir + '/');
|
|
|
|
}
|
|
|
|
|
2016-09-12 14:53:04 +03:00
|
|
|
function getProtectedSlugs() {
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
var subDir = getSubdir();
|
2016-09-12 14:53:04 +03:00
|
|
|
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
if (!_.isEmpty(subDir)) {
|
|
|
|
return config.get('slugs').protected.concat([subDir.split('/').pop()]);
|
2016-09-12 14:53:04 +03:00
|
|
|
} else {
|
2016-09-13 18:41:14 +03:00
|
|
|
return config.get('slugs').protected;
|
2016-09-12 14:53:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-23 11:22:37 +03:00
|
|
|
/** urlJoin
|
|
|
|
* Returns a URL/path for internal use in Ghost.
|
|
|
|
* @param {string} arguments takes arguments and concats those to a valid path/URL.
|
|
|
|
* @return {string} URL concatinated URL/path of arguments.
|
|
|
|
*/
|
2015-04-10 18:59:38 +03:00
|
|
|
function urlJoin() {
|
|
|
|
var args = Array.prototype.slice.call(arguments),
|
|
|
|
prefixDoubleSlash = false,
|
|
|
|
url;
|
|
|
|
|
|
|
|
// Remove empty item at the beginning
|
|
|
|
if (args[0] === '') {
|
|
|
|
args.shift();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle schemeless protocols
|
|
|
|
if (args[0].indexOf('//') === 0) {
|
|
|
|
prefixDoubleSlash = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// join the elements using a slash
|
|
|
|
url = args.join('/');
|
|
|
|
|
|
|
|
// Fix multiple slashes
|
|
|
|
url = url.replace(/(^|[^:])\/\/+/g, '$1/');
|
|
|
|
|
|
|
|
// Put the double slash back at the beginning if this was a schemeless protocol
|
|
|
|
if (prefixDoubleSlash) {
|
|
|
|
url = url.replace(/^\//, '//');
|
|
|
|
}
|
|
|
|
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
url = deduplicateSubDir(url);
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* admin:url is optional
|
|
|
|
*/
|
|
|
|
function getAdminUrl() {
|
|
|
|
var adminUrl = config.get('admin:url'),
|
|
|
|
subDir = getSubdir();
|
|
|
|
|
|
|
|
if (!adminUrl) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!adminUrl.match(/\/$/)) {
|
|
|
|
adminUrl += '/';
|
2015-04-10 18:59:38 +03:00
|
|
|
}
|
|
|
|
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
adminUrl = urlJoin(adminUrl, subDir, '/');
|
|
|
|
adminUrl = deduplicateSubDir(adminUrl);
|
|
|
|
return adminUrl;
|
2015-04-10 18:59:38 +03:00
|
|
|
}
|
|
|
|
|
2014-01-03 04:37:21 +04:00
|
|
|
// ## createUrl
|
|
|
|
// Simple url creation from a given path
|
|
|
|
// Ensures that our urls contain the subdirectory if there is one
|
|
|
|
// And are correctly formatted as either relative or absolute
|
|
|
|
// Usage:
|
|
|
|
// createUrl('/', true) -> http://my-ghost-blog.com/
|
|
|
|
// E.g. /blog/ subdir
|
|
|
|
// createUrl('/welcome-to-ghost/') -> /blog/welcome-to-ghost/
|
|
|
|
// Parameters:
|
|
|
|
// - urlPath - string which must start and end with a slash
|
|
|
|
// - absolute (optional, default:false) - boolean whether or not the url should be absolute
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
// - secure (optional, default:false) - boolean whether or not to force SSL
|
2014-01-03 04:37:21 +04:00
|
|
|
// Returns:
|
|
|
|
// - a URL which always ends with a slash
|
2014-02-22 05:25:31 +04:00
|
|
|
function createUrl(urlPath, absolute, secure) {
|
2014-01-03 04:37:21 +04:00
|
|
|
urlPath = urlPath || '/';
|
|
|
|
absolute = absolute || false;
|
2015-04-10 18:59:38 +03:00
|
|
|
var base;
|
2014-01-03 04:37:21 +04:00
|
|
|
|
|
|
|
// create base of url, always ends without a slash
|
|
|
|
if (absolute) {
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
base = getBlogUrl(secure);
|
2014-01-03 04:37:21 +04:00
|
|
|
} else {
|
2016-09-12 14:53:04 +03:00
|
|
|
base = getSubdir();
|
2014-01-03 04:37:21 +04:00
|
|
|
}
|
|
|
|
|
2015-04-10 18:59:38 +03:00
|
|
|
return urlJoin(base, urlPath);
|
2014-01-03 04:37:21 +04:00
|
|
|
}
|
|
|
|
|
2016-05-18 17:27:54 +03:00
|
|
|
/**
|
|
|
|
* creates the url path for a post based on blog timezone and permalink pattern
|
|
|
|
*
|
|
|
|
* @param {JSON} post
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2015-12-02 13:06:44 +03:00
|
|
|
function urlPathForPost(post) {
|
2014-01-03 04:37:21 +04:00
|
|
|
var output = '',
|
2017-02-03 16:15:11 +03:00
|
|
|
permalinks = settingsCache.get('permalinks'),
|
2018-04-17 12:36:05 +03:00
|
|
|
// routeKeywords.primaryTagFallback: 'all'
|
|
|
|
primaryTagFallback = 'all',
|
|
|
|
// routeKeywords.primaryAuthorFallback: 'all'
|
|
|
|
primaryAuthorFallback = 'all',
|
2017-04-24 20:41:00 +03:00
|
|
|
publishedAtMoment = moment.tz(post.published_at || Date.now(), settingsCache.get('active_timezone')),
|
2014-01-03 04:37:21 +04:00
|
|
|
tags = {
|
2017-12-11 21:14:05 +03:00
|
|
|
year: function () {
|
|
|
|
return publishedAtMoment.format('YYYY');
|
|
|
|
},
|
|
|
|
month: function () {
|
|
|
|
return publishedAtMoment.format('MM');
|
|
|
|
},
|
|
|
|
day: function () {
|
|
|
|
return publishedAtMoment.format('DD');
|
|
|
|
},
|
2018-03-27 17:16:15 +03:00
|
|
|
/**
|
|
|
|
* @deprecated: `author`, will be removed in Ghost 2.0
|
|
|
|
*/
|
2017-12-11 21:14:05 +03:00
|
|
|
author: function () {
|
|
|
|
return post.author.slug;
|
|
|
|
},
|
|
|
|
primary_tag: function () {
|
|
|
|
return post.primary_tag ? post.primary_tag.slug : primaryTagFallback;
|
|
|
|
},
|
2018-03-27 17:16:15 +03:00
|
|
|
primary_author: function () {
|
|
|
|
return post.primary_author ? post.primary_author.slug : primaryAuthorFallback;
|
|
|
|
},
|
2017-12-11 21:14:05 +03:00
|
|
|
slug: function () {
|
|
|
|
return post.slug;
|
|
|
|
},
|
|
|
|
id: function () {
|
|
|
|
return post.id;
|
|
|
|
}
|
2014-01-03 04:37:21 +04:00
|
|
|
};
|
|
|
|
|
2014-06-12 13:44:10 +04:00
|
|
|
if (post.page) {
|
2014-01-03 04:37:21 +04:00
|
|
|
output += '/:slug/';
|
|
|
|
} else {
|
2014-12-10 17:03:39 +03:00
|
|
|
output += permalinks;
|
2014-01-03 04:37:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// replace tags like :slug or :year with actual values
|
2017-07-31 12:00:03 +03:00
|
|
|
output = output.replace(/(:[a-z_]+)/g, function (match) {
|
2014-01-03 04:37:21 +04:00
|
|
|
if (_.has(tags, match.substr(1))) {
|
|
|
|
return tags[match.substr(1)]();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ## urlFor
|
|
|
|
// Synchronous url creation for a given context
|
|
|
|
// Can generate a url for a named path, given path, or known object (post)
|
|
|
|
// Determines what sort of context it has been given, and delegates to the correct generation method,
|
|
|
|
// Finally passing to createUrl, to ensure any subdirectory is honoured, and the url is absolute if needed
|
|
|
|
// Usage:
|
|
|
|
// urlFor('home', true) -> http://my-ghost-blog.com/
|
|
|
|
// E.g. /blog/ subdir
|
2015-03-26 10:01:39 +03:00
|
|
|
// urlFor({relativeUrl: '/my-static-page/'}) -> /blog/my-static-page/
|
2014-01-03 04:37:21 +04:00
|
|
|
// E.g. if post object represents welcome post, and slugs are set to standard
|
|
|
|
// urlFor('post', {...}) -> /welcome-to-ghost/
|
|
|
|
// E.g. if post object represents welcome post, and slugs are set to date
|
|
|
|
// urlFor('post', {...}) -> /2014/01/01/welcome-to-ghost/
|
|
|
|
// Parameters:
|
|
|
|
// - context - a string, or json object describing the context for which you need a url
|
|
|
|
// - data (optional) - a json object containing data needed to generate a url
|
|
|
|
// - absolute (optional, default:false) - boolean whether or not the url should be absolute
|
|
|
|
// This is probably not the right place for this, but it's the best place for now
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
// @TODO: rewrite, very hard to read, create private functions!
|
2014-01-03 04:37:21 +04:00
|
|
|
function urlFor(context, data, absolute) {
|
|
|
|
var urlPath = '/',
|
2014-10-21 14:50:34 +04:00
|
|
|
secure, imagePathRe,
|
2015-01-28 08:57:19 +03:00
|
|
|
knownObjects = ['post', 'tag', 'author', 'image', 'nav'], baseUrl,
|
|
|
|
hostname,
|
2014-05-02 03:42:23 +04:00
|
|
|
|
2017-11-01 16:44:54 +03:00
|
|
|
// this will become really big
|
|
|
|
knownPaths = {
|
|
|
|
home: '/',
|
|
|
|
rss: '/rss/',
|
|
|
|
api: API_PATH,
|
|
|
|
sitemap_xsl: '/sitemap.xsl'
|
|
|
|
};
|
2014-01-03 04:37:21 +04:00
|
|
|
|
|
|
|
// Make data properly optional
|
|
|
|
if (_.isBoolean(data)) {
|
|
|
|
absolute = data;
|
|
|
|
data = null;
|
|
|
|
}
|
|
|
|
|
2014-02-22 05:25:31 +04:00
|
|
|
// Can pass 'secure' flag in either context or data arg
|
|
|
|
secure = (context && context.secure) || (data && data.secure);
|
|
|
|
|
2014-01-03 04:37:21 +04:00
|
|
|
if (_.isObject(context) && context.relativeUrl) {
|
|
|
|
urlPath = context.relativeUrl;
|
|
|
|
} else if (_.isString(context) && _.indexOf(knownObjects, context) !== -1) {
|
|
|
|
// trying to create a url for an object
|
2014-12-10 17:03:39 +03:00
|
|
|
if (context === 'post' && data.post) {
|
|
|
|
urlPath = data.post.url;
|
|
|
|
secure = data.secure;
|
2014-02-13 20:15:29 +04:00
|
|
|
} else if (context === 'tag' && data.tag) {
|
2018-04-17 12:36:05 +03:00
|
|
|
// routeKeywords.tag: 'tag'
|
|
|
|
urlPath = urlJoin('/tag', data.tag.slug, '/');
|
2014-02-22 05:25:31 +04:00
|
|
|
secure = data.tag.secure;
|
2014-07-20 20:41:59 +04:00
|
|
|
} else if (context === 'author' && data.author) {
|
2018-04-17 12:36:05 +03:00
|
|
|
// routeKeywords.author: 'author'
|
|
|
|
urlPath = urlJoin('/author', data.author.slug, '/');
|
2014-07-20 20:41:59 +04:00
|
|
|
secure = data.author.secure;
|
2014-10-21 14:50:34 +04:00
|
|
|
} else if (context === 'image' && data.image) {
|
|
|
|
urlPath = data.image;
|
2017-02-03 17:42:05 +03:00
|
|
|
imagePathRe = new RegExp('^' + getSubdir() + '/' + STATIC_IMAGE_URL_PREFIX);
|
2014-10-21 14:50:34 +04:00
|
|
|
absolute = imagePathRe.test(data.image) ? absolute : false;
|
2014-11-17 06:38:10 +03:00
|
|
|
|
2014-12-02 17:24:51 +03:00
|
|
|
if (absolute) {
|
|
|
|
// Remove the sub-directory from the URL because ghostConfig will add it back.
|
2016-09-12 14:53:04 +03:00
|
|
|
urlPath = urlPath.replace(new RegExp('^' + getSubdir()), '');
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
baseUrl = getBlogUrl(secure).replace(/\/$/, '');
|
2014-12-02 17:24:51 +03:00
|
|
|
urlPath = baseUrl + urlPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
return urlPath;
|
2015-01-28 08:57:19 +03:00
|
|
|
} else if (context === 'nav' && data.nav) {
|
|
|
|
urlPath = data.nav.url;
|
2016-01-05 21:04:39 +03:00
|
|
|
secure = data.nav.secure || secure;
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
baseUrl = getBlogUrl(secure);
|
2017-11-02 23:35:58 +03:00
|
|
|
hostname = baseUrl.split('//')[1];
|
2016-09-13 18:41:14 +03:00
|
|
|
|
2017-11-02 23:35:58 +03:00
|
|
|
// If the hostname is present in the url
|
2015-07-18 04:45:06 +03:00
|
|
|
if (urlPath.indexOf(hostname) > -1
|
2017-11-02 23:35:58 +03:00
|
|
|
// do no not apply, if there is a subdomain, or a mailto link
|
2016-07-21 16:05:13 +03:00
|
|
|
&& !urlPath.split(hostname)[0].match(/\.|mailto:/)
|
2017-11-02 23:35:58 +03:00
|
|
|
// do not apply, if there is a port after the hostname
|
2017-11-01 16:44:54 +03:00
|
|
|
&& urlPath.split(hostname)[1].substring(0, 1) !== ':') {
|
2017-11-02 23:35:58 +03:00
|
|
|
// make link relative to account for possible mismatch in http/https etc, force absolute
|
2015-03-20 06:00:32 +03:00
|
|
|
urlPath = urlPath.split(hostname)[1];
|
2017-11-02 23:35:58 +03:00
|
|
|
urlPath = urlJoin('/', urlPath);
|
2015-01-28 08:57:19 +03:00
|
|
|
absolute = true;
|
|
|
|
}
|
2014-01-03 04:37:21 +04:00
|
|
|
}
|
2017-02-02 21:51:35 +03:00
|
|
|
} else if (context === 'home' && absolute) {
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
urlPath = getBlogUrl(secure);
|
|
|
|
|
2017-06-19 17:11:53 +03:00
|
|
|
// CASE: there are cases where urlFor('home') needs to be returned without trailing
|
|
|
|
// slash e. g. the `{{@blog.url}}` helper. See https://github.com/TryGhost/Ghost/issues/8569
|
|
|
|
if (data && data.trailingSlash === false) {
|
|
|
|
urlPath = urlPath.replace(/\/$/, '');
|
|
|
|
}
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
} else if (context === 'admin') {
|
|
|
|
urlPath = getAdminUrl() || getBlogUrl();
|
2017-02-02 21:51:35 +03:00
|
|
|
|
|
|
|
if (absolute) {
|
|
|
|
urlPath += 'ghost/';
|
|
|
|
} else {
|
|
|
|
urlPath = '/ghost/';
|
|
|
|
}
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
} else if (context === 'api') {
|
|
|
|
urlPath = getAdminUrl() || getBlogUrl();
|
|
|
|
|
2017-09-18 18:28:22 +03:00
|
|
|
// CASE: with or without protocol? If your blog url (or admin url) is configured to http, it's still possible that e.g. nginx allows both https+http.
|
|
|
|
// So it depends how you serve your blog. The main focus here is to avoid cors problems.
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
// @TODO: rename cors
|
|
|
|
if (data && data.cors) {
|
2017-09-18 18:28:22 +03:00
|
|
|
if (!urlPath.match(/^https:/)) {
|
|
|
|
urlPath = urlPath.replace(/^.*?:\/\//g, '//');
|
|
|
|
}
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (absolute) {
|
|
|
|
urlPath = urlPath.replace(/\/$/, '') + API_PATH;
|
|
|
|
} else {
|
|
|
|
urlPath = API_PATH;
|
|
|
|
}
|
2014-01-03 04:37:21 +04:00
|
|
|
} else if (_.isString(context) && _.indexOf(_.keys(knownPaths), context) !== -1) {
|
|
|
|
// trying to create a url for a named path
|
2017-11-02 23:35:58 +03:00
|
|
|
urlPath = knownPaths[context];
|
2014-01-03 04:37:21 +04:00
|
|
|
}
|
|
|
|
|
2015-02-13 02:09:12 +03:00
|
|
|
// This url already has a protocol so is likely an external url to be returned
|
2015-09-26 00:31:54 +03:00
|
|
|
// or it is an alternative scheme, protocol-less, or an anchor-only path
|
|
|
|
if (urlPath && (urlPath.indexOf('://') !== -1 || urlPath.match(/^(\/\/|#|[a-zA-Z0-9\-]+:)/))) {
|
2015-02-13 02:09:12 +03:00
|
|
|
return urlPath;
|
|
|
|
}
|
|
|
|
|
2014-02-22 05:25:31 +04:00
|
|
|
return createUrl(urlPath, absolute, secure);
|
2014-01-03 04:37:21 +04:00
|
|
|
}
|
|
|
|
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
function isSSL(urlToParse) {
|
|
|
|
var protocol = url.parse(urlToParse).protocol;
|
|
|
|
return protocol === 'https:';
|
2015-12-15 13:41:53 +03:00
|
|
|
}
|
|
|
|
|
2017-10-12 15:36:50 +03:00
|
|
|
function redirect301(res, redirectUrl) {
|
|
|
|
res.set({'Cache-Control': 'public, max-age=' + config.get('caching:301:maxAge')});
|
|
|
|
return res.redirect(301, redirectUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
function redirectToAdmin(status, res, adminPath) {
|
|
|
|
var redirectUrl = urlJoin(urlFor('admin'), adminPath, '/');
|
|
|
|
|
|
|
|
if (status === 301) {
|
|
|
|
return redirect301(res, redirectUrl);
|
|
|
|
}
|
|
|
|
return res.redirect(redirectUrl);
|
|
|
|
}
|
|
|
|
|
2017-12-15 00:32:34 +03:00
|
|
|
/**
|
|
|
|
* Make absolute URLs
|
|
|
|
* @param {string} html
|
|
|
|
* @param {string} siteUrl (blog URL)
|
|
|
|
* @param {string} itemUrl (URL of current context)
|
|
|
|
* @returns {object} htmlContent
|
|
|
|
* @description Takes html, blog url and item url and converts relative url into
|
|
|
|
* absolute urls. Returns an object. The html string can be accessed by calling `html()` on
|
|
|
|
* the variable that takes the result of this function
|
|
|
|
*/
|
|
|
|
function makeAbsoluteUrls(html, siteUrl, itemUrl) {
|
|
|
|
var htmlContent = cheerio.load(html, {decodeEntities: false});
|
|
|
|
|
|
|
|
// convert relative resource urls to absolute
|
|
|
|
['href', 'src'].forEach(function forEach(attributeName) {
|
|
|
|
htmlContent('[' + attributeName + ']').each(function each(ix, el) {
|
|
|
|
var baseUrl,
|
|
|
|
attributeValue,
|
|
|
|
parsed;
|
|
|
|
|
|
|
|
el = htmlContent(el);
|
|
|
|
|
|
|
|
attributeValue = el.attr(attributeName);
|
|
|
|
|
|
|
|
// if URL is absolute move on to the next element
|
|
|
|
try {
|
|
|
|
parsed = url.parse(attributeValue);
|
|
|
|
|
|
|
|
if (parsed.protocol) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do not convert protocol relative URLs
|
|
|
|
if (attributeValue.lastIndexOf('//', 0) === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CASE: don't convert internal links
|
|
|
|
if (attributeValue[0] === '#') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// compose an absolute URL
|
|
|
|
|
|
|
|
// if the relative URL begins with a '/' use the blog URL (including sub-directory)
|
|
|
|
// as the base URL, otherwise use the post's URL.
|
|
|
|
baseUrl = attributeValue[0] === '/' ? siteUrl : itemUrl;
|
|
|
|
attributeValue = urlJoin(baseUrl, attributeValue);
|
|
|
|
el.attr(attributeName, attributeValue);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return htmlContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.makeAbsoluteUrls = makeAbsoluteUrls;
|
2016-09-12 14:53:04 +03:00
|
|
|
module.exports.getProtectedSlugs = getProtectedSlugs;
|
|
|
|
module.exports.getSubdir = getSubdir;
|
2015-04-10 18:59:38 +03:00
|
|
|
module.exports.urlJoin = urlJoin;
|
2014-01-03 04:37:21 +04:00
|
|
|
module.exports.urlFor = urlFor;
|
🔥✨ remove forceAdminSSL and urlSSL, add admin url (#7937)
* 🔥 kill apiUrl helper, use urlFor helper instead
More consistency of creating urls.
Creates an easier ability to add config changes.
Attention: urlFor function is getting a little nesty, BUT that is for now wanted to make easier and centralised changes to the configs.
The url util need's refactoring anyway.
* 🔥 urlSSL
Remove all urlSSL usages.
Add TODO's for the next commit to re-add logic for deleted logic.
e.g.
- cors helper generated an array of url's to allow requests from the defined config url's -> will be replaced by the admin url if available
- theme handler prefered the urlSSL in case it was defined -> will be replaced by using the urlFor helper to get the blog url (based on the request secure flag)
The changes in this commit doesn't have to be right, but it helped going step by step.
The next commit is the more interesting one.
* 🔥 ✨ remove forceAdminSSL, add new admin url and adapt logic
I wanted to remove the forceAdminSSL as separate commit, but was hard to realise.
That's why both changes are in one commit:
1. remove forceAdminSSL
2. add admin.url option
- fix TODO's from last commits
- rewrite the ssl middleware!
- create some private helper functions in the url helper to realise the changes
- rename some wordings and functions e.g. base === blog (we have so much different wordings)
- i would like to do more, but this would end in a non readable PR
- this commit contains the most important changes to offer admin.url option
* 🤖 adapt tests
IMPORTANT
- all changes in the routing tests were needed, because each routing test did not start the ghost server
- they just required the ghost application, which resulted in a random server port
- having a random server port results in a redirect, caused by the ssl/redirect middleware
* 😎 rename check-ssl middleware
* 🎨 fix theme-handler because of master rebase
2017-02-03 21:13:22 +03:00
|
|
|
module.exports.isSSL = isSSL;
|
2014-12-10 17:03:39 +03:00
|
|
|
module.exports.urlPathForPost = urlPathForPost;
|
2017-10-12 15:36:50 +03:00
|
|
|
module.exports.redirectToAdmin = redirectToAdmin;
|
|
|
|
module.exports.redirect301 = redirect301;
|
2018-04-17 16:36:51 +03:00
|
|
|
module.exports.createUrl = createUrl;
|
2017-02-03 17:42:05 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If you request **any** image in Ghost, it get's served via
|
|
|
|
* http://your-blog.com/content/images/2017/01/02/author.png
|
|
|
|
*
|
|
|
|
* /content/images/ is a static prefix for serving images!
|
|
|
|
*
|
|
|
|
* But internally the image is located for example in your custom content path:
|
|
|
|
* my-content/another-dir/images/2017/01/02/author.png
|
|
|
|
*/
|
|
|
|
module.exports.STATIC_IMAGE_URL_PREFIX = STATIC_IMAGE_URL_PREFIX;
|