add experimental custom domain support

This commit is contained in:
Kyle Drake 2013-07-27 00:07:06 -04:00
parent 237ce5f419
commit 8014a21c2c
8 changed files with 103 additions and 2 deletions

1
.gitignore vendored
View file

@ -19,3 +19,4 @@ doc/
tests/coverage tests/coverage
config.yml config.yml
.DS_Store .DS_Store
domains

27
app.rb
View file

@ -503,6 +503,33 @@ get '/password_reset_confirm' do
redirect '/' redirect '/'
end end
get '/custom_domain' do
slim :custom_domain
end
post '/custom_domain' do
require_login
original_domain = current_site.domain
current_site.domain = params[:domain]
if current_site.valid?
DB.transaction do
current_site.save
if !params[:domain].empty? && !params[:domain].nil?
File.open(File.join(DIR_ROOT, 'domains', "#{current_site.username}.conf"), 'w') do |file|
file.write erb(:'templates/domain', layout: false)
end
end
end
flash[:success] = 'The domain has been successfully updated.'
redirect '/custom_domain'
else
slim :custom_domain
end
end
get '/contact' do get '/contact' do
slim :'contact' slim :'contact'
end end

View file

@ -4,6 +4,6 @@ Sequel.migration do
} }
down { down {
DB.add_column :sites, :is_nsfw DB.drop_column :sites, :is_nsfw
} }
end end

View file

@ -0,0 +1,9 @@
Sequel.migration do
up {
DB.add_column :sites, :domain, :text, default: nil
}
down {
DB.drop_column :sites, :domain
}
end

View file

@ -95,6 +95,13 @@ class Site < Sequel::Model
if values[:password].nil? || (@password_length && @password_length < MINIMUM_PASSWORD_LENGTH) if values[:password].nil? || (@password_length && @password_length < MINIMUM_PASSWORD_LENGTH)
errors.add :password, "Password must be at least #{MINIMUM_PASSWORD_LENGTH} characters." errors.add :password, "Password must be at least #{MINIMUM_PASSWORD_LENGTH} characters."
end end
if !values[:domain].nil? && !values[:domain].empty?
if !(values[:domain] =~ /^[a-zA-Z0-9]+\.[a-zA-Z0-9]+$/i)
errors.add :domain, "Domain provided is not valid. Must take the form of domain.com"
end
end
end end
def file_path def file_path

27
views/custom_domain.slim Normal file
View file

@ -0,0 +1,27 @@
.page
.content
h1.txt-Center Custom Domain
h3.txt-Center (advanced)
.txt-Center
- if !current_site.errors.empty?
.alert.alert-block.alert-error
- current_site.errors.each do |error|
p = error.last.first
.row.c-Row
.col.col-66
.content
p Adding a custom domain allows you to have a domain name attached to your web site. So if you had a domain like <strong>catsknitting.com</strong>, you could have it point to your NeoCities site!
p You will have to purchase a domain name from a registrar like <a href="https://namecheap.com" target="_blank">Namecheap</a>, and then add an A record to point your domain (catsknitting.com) to the following IP address:
p <code>5.9.136.200</code>
p If you want to add a <strong>www</strong> subdomain, or use a wildcard that will answer to everything (<strong>*</strong>), you will have to make a CNAME pointing to <strong>catsknitting.com</strong> for <strong>www</strong> and/or <strong>*</strong>.
p After that, you can add the domain to the box below (just the <strong>catsknitting.com</strong>, don't add any subdomains), and your domain should come online within 5 minutes:
form method="POST" action="/custom_domain"
input name="csrf_token" type="hidden" value="#{csrf_token}"
input name="domain" type="text" placeholder="catsknitting.com" value="#{current_site.domain}"
br
input.btn-Action type="submit" value="Update Domain"
p <strong>NOTE: This is for advanced users, we cannot provide technical support for this feature.</strong> If you cannot make this work, please contact your domain registrar.

View file

@ -57,3 +57,10 @@
p: strong My page contains objectionable (adult) content:&nbsp;&nbsp;&nbsp;<input name="is_nsfw" type="checkbox" value="true" style="margin-top: 0px" #{"checked" if current_site.is_nsfw}> p: strong My page contains objectionable (adult) content:&nbsp;&nbsp;&nbsp;<input name="is_nsfw" type="checkbox" value="true" style="margin-top: 0px" #{"checked" if current_site.is_nsfw}>
input.btn-Action type="submit" value="Update" input.btn-Action type="submit" value="Update"
.row
.col.col-33
.content
h2.eps.txt-Center Custom Domain
p.txt-Center: strong (advanced)
p You can configure a custom domain for your NeoCities site. <strong><a href="/custom_domain">Click Here</a></strong> for more information.

View file

@ -0,0 +1,23 @@
server {
listen 80;
server_name <%= current_site.domain %> *.<%= current_site.domain %>
access_log /var/log/nginx/neocities-domains.log neocitiesdomain;
root /home/web/neocities-web/public/sites/<%= current_site.username %>;
index /index.html;
error_page 404 = @notfound;
location @notfound {
try_files /not_found.html @notfound_root;
}
location @notfound_root {
root /home/web/neocities-web/public;
try_files /web_site_not_found.html =404;
}
location ~* \.(html|jpg|jpeg|png|gif|ico|css|js)$ {
# expires 20s;
log_not_found off;
}
}