mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
add experimental custom domain support
This commit is contained in:
parent
237ce5f419
commit
8014a21c2c
8 changed files with 103 additions and 2 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -19,3 +19,4 @@ doc/
|
|||
tests/coverage
|
||||
config.yml
|
||||
.DS_Store
|
||||
domains
|
||||
|
|
27
app.rb
27
app.rb
|
@ -503,6 +503,33 @@ get '/password_reset_confirm' do
|
|||
redirect '/'
|
||||
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
|
||||
slim :'contact'
|
||||
end
|
||||
|
|
|
@ -4,6 +4,6 @@ Sequel.migration do
|
|||
}
|
||||
|
||||
down {
|
||||
DB.add_column :sites, :is_nsfw
|
||||
DB.drop_column :sites, :is_nsfw
|
||||
}
|
||||
end
|
9
migrations/017_add_domain.rb
Normal file
9
migrations/017_add_domain.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
Sequel.migration do
|
||||
up {
|
||||
DB.add_column :sites, :domain, :text, default: nil
|
||||
}
|
||||
|
||||
down {
|
||||
DB.drop_column :sites, :domain
|
||||
}
|
||||
end
|
|
@ -95,6 +95,13 @@ class Site < Sequel::Model
|
|||
if values[:password].nil? || (@password_length && @password_length < MINIMUM_PASSWORD_LENGTH)
|
||||
errors.add :password, "Password must be at least #{MINIMUM_PASSWORD_LENGTH} characters."
|
||||
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
|
||||
|
||||
def file_path
|
||||
|
|
27
views/custom_domain.slim
Normal file
27
views/custom_domain.slim
Normal 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.
|
|
@ -57,3 +57,10 @@
|
|||
p: strong My page contains objectionable (adult) content: <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"
|
||||
|
||||
.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.
|
23
views/templates/domain.erb
Normal file
23
views/templates/domain.erb
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue