diff --git a/generator/app/index.js b/generator/app/index.js
index f45f998..75155a8 100644
--- a/generator/app/index.js
+++ b/generator/app/index.js
@@ -66,12 +66,26 @@ WordpressGenerator.prototype.promptForName = function() {
};
WordpressGenerator.prototype.promptForDomain = function() {
+ var existing = function() {
+ try {
+ var groupVars = this.readFileAsString(path.join(this.env.cwd, 'provisioning', 'group_vars', 'webservers'));
+
+ var matches = groupVars.match(/^domain:[\t ]*(\S+)\s/m);
+
+ if (matches) {
+ return matches[1];
+ }
+ } catch(e) {};
+ }.bind(this);
+
this.prompts.push({
required: true,
type: 'text',
name: 'domain',
message: 'Domain name (e.g. mysite.com)',
- default: path.basename(this.env.cwd).toLowerCase(),
+ default: function() {
+ return existing() || path.basename(this.env.cwd).toLowerCase();
+ }.bind(this),
validate: function(input) {
if (/^[\w-]+\.\w+(?:\.\w{2,3})?$/.test(input)) {
return true;
@@ -84,6 +98,42 @@ WordpressGenerator.prototype.promptForDomain = function() {
});
};
+WordpressGenerator.prototype.promptForAliases = function() {
+ var existing = function() {
+ try {
+ var groupVars = this.readFileAsString(path.join(this.env.cwd, 'provisioning', 'group_vars', 'webservers'));
+
+ var matches = groupVars.match(/^aliases:(?:\s+-[ ]+\S+)+/m);
+
+ if (matches) {
+ var aliases = matches[0].split(/\s+-[ ]+/);
+ aliases.shift();
+
+ return aliases.join(' ');
+ }
+ } catch(e) {};
+ }.bind(this);
+
+ this.prompts.push({
+ required: true,
+ type: 'text',
+ name: 'aliases',
+ message: 'Domain aliases, space delimited (e.g. mysite.net mysite.org)',
+ default: function() {
+ return existing() || '';
+ }.bind(this),
+ validate: function(input) {
+ if (/^([\w-]+\.\w+(?:\.\w{2,3})?(?:[ ]+)?)+$/.test(input)) {
+ return true;
+ } else if (!input) {
+ return true;
+ }
+
+ return chalk.yellow(input) + ' does not match the example';
+ }
+ });
+};
+
WordpressGenerator.prototype.promptForGenesis = function() {
this.prompts.push({
type: 'text',
diff --git a/generator/app/templates/Vagrantfile b/generator/app/templates/Vagrantfile
index 7b65242..0f60f92 100644
--- a/generator/app/templates/Vagrantfile
+++ b/generator/app/templates/Vagrantfile
@@ -18,7 +18,8 @@ Vagrant.configure("2") do |config|
config.vm.define :local do |box|
box.vm.hostname = "local.<%= props.domain %>"
-
+<% if (props.aliases) { %> box.hostmanager.aliases = %w(<%= props.aliases.split(/\s+/).map(function (alias) { return 'local.' + alias; }).join(' ') %>)
+<% } %>
# Static IP for testing.
box.vm.network :private_network, ip: "<%= props.ip %>"
box.vm.network :forwarded_port, guest: 22, host: <%= props.ip.split('.').join('').split('0').join('').slice(-4) %>, auto_correct: true
diff --git a/generator/app/templates/provisioning/group_vars/webservers b/generator/app/templates/provisioning/group_vars/webservers
index c47f2df..624e224 100644
--- a/generator/app/templates/provisioning/group_vars/webservers
+++ b/generator/app/templates/provisioning/group_vars/webservers
@@ -1,5 +1,7 @@
---
domain: <%= props.domain %>
+aliases:<% if (props.aliases) { props.aliases.split(/\s+/).forEach(function (alias) { %>
+ - <%= alias %><% }); } else { %> []<% } %>
mysql:
name: <%= props.DB_NAME %>
user: <%= props.DB_USER %>
diff --git a/generator/app/templates/web/htaccess b/generator/app/templates/web/htaccess
index d501765..b15850b 100644
--- a/generator/app/templates/web/htaccess
+++ b/generator/app/templates/web/htaccess
@@ -126,7 +126,14 @@ SetEnvIf Host ^local\. allow_wp_install
# Rules to help reduce spam
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} ^(.*)wp-comments-post\.php*
- RewriteCond %{HTTP_REFERER} !^(.*)<%= props.domain %>.*
+ RewriteCond %{HTTP_REFERER} !^(.*)<%
+if (props.aliases) {
+ %>(<%= props.domain %>|<%
+ %><%= props.aliases.split(/\s+/).join('|') %>)<%
+} else {
+ %><%= props.domain %><%
+}
+%>.*
RewriteCond %{HTTP_REFERER} !^http://jetpack\.wordpress\.com/jetpack-comment/ [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule ^(.*)$ - [F]
diff --git a/provisioning/roles/wordpress/templates/vhosts/000-local b/provisioning/roles/wordpress/templates/vhosts/000-local
index 8951e01..4d89d90 100644
--- a/provisioning/roles/wordpress/templates/vhosts/000-local
+++ b/provisioning/roles/wordpress/templates/vhosts/000-local
@@ -3,6 +3,10 @@
ServerName local.{{ domain }}
+{% for alias in aliases %}
+ ServerAlias local.{{ alias }}
+{% endfor %}
+
DocumentRoot /vagrant/web
Options FollowSymLinks
diff --git a/provisioning/roles/wordpress/templates/vhosts/001-staging b/provisioning/roles/wordpress/templates/vhosts/001-staging
index 452f68e..6ded2dc 100644
--- a/provisioning/roles/wordpress/templates/vhosts/001-staging
+++ b/provisioning/roles/wordpress/templates/vhosts/001-staging
@@ -3,6 +3,10 @@
ServerName staging.{{ domain }}
+{% for alias in aliases %}
+ ServerAlias staging.{{ alias }}
+{% endfor %}
+
DocumentRoot /var/www/{{ domain }}/master/current/web
Options FollowSymLinks
diff --git a/provisioning/roles/wordpress/templates/vhosts/002-branch b/provisioning/roles/wordpress/templates/vhosts/002-branch
index f7b3874..e6ae362 100644
--- a/provisioning/roles/wordpress/templates/vhosts/002-branch
+++ b/provisioning/roles/wordpress/templates/vhosts/002-branch
@@ -4,6 +4,10 @@
ServerName branch.staging.{{ domain }}
ServerAlias *.staging.{{ domain }}
+{% for alias in aliases %}
+ ServerAlias branch.staging.{{ alias }} *.staging.{{ alias }}
+{% endfor %}
+
VirtualDocumentRoot /var/www/{{ domain }}/%1/current/web
Options FollowSymLinks
diff --git a/provisioning/roles/wordpress/templates/vhosts/003-production b/provisioning/roles/wordpress/templates/vhosts/003-production
index f84a6d9..7be98f2 100644
--- a/provisioning/roles/wordpress/templates/vhosts/003-production
+++ b/provisioning/roles/wordpress/templates/vhosts/003-production
@@ -7,6 +7,10 @@
ServerAlias www.{{ domain }}
ServerAlias *.{{ domain }}
+{% for alias in aliases %}
+ ServerAlias {{ alias }} production.{{ alias }} www.{{ alias }} *.{{ alias }}
+{% endfor %}
+
DocumentRoot /var/www/{{ domain }}/master/current/web
Options FollowSymLinks