Basic HTTP Authentication for a Middleman app - ruby

I wonder whether there's an easy way to add Basic HTTP Authentication to a Middleman deployed website? I found some Heroku specific gists, but nothing else.
The Heroku specific gists all seem to need a config.ru file, but do Middleman projects even have such a file? Mine don't.

config.ru is not specific to Middleman or Heroku, but is a convention for serving a rack-based app (see https://devcenter.heroku.com/articles/rack). If you want to have basic auth on a static site that you have built using middleman and then deployed, you will need to set it up in a way that's appropriate to that hosting. Where are you hosting the site?

Related

Deploy ember-cli and rails api

I'm looking for a way to deploy on Heroku a Rails API and an ember-cli application. My directories structure is something like that:
application
frontend
rails-api
Can someone help me? I'm really new Heroku user.
PS: I don't want to use gems like 'ember-cli-rails'
I would deploy them separately, and keep them in separate git repos.
Ember
Use ember-cli-deploy. I would suggest you look into the ember-cli-deploy-lightning-pack. There is a presentation about it here.
This automates the release process -
Builds your Ember app, with asset fingerprints
gzips the assets
Uploads changed files to AWS S3
Puts the full content of your index.html into Redis
Rails
deploy your rails-api app to heroku normally
include a redis addon
set up the route which serves index.html to query it directly from Redis instead
I would suggest aliasing all non-api routes (ie a catchall route) to the root route so you can 'deep link' to your ember app
A big advantage of this process is that you can deploy changes to your frontend very quickly, and without having to take down or restart the server.

How do you access assets in a Pakyow app on heroku?

Problem: Pakyow App deployed to Heroku and all JS and CSS sourced/linked in template head 404.
I assume this is a problem stemming from Heroku, but rather not one that I am aware of. As far as I know, Heroku allows static assets in the public directory.
Anyway, looking for some helpful pointers from Pakyow users.
The app (currently) is at http://pakyow-go.herokuapp.com and the repo can be found at http://github.com/jphager2/pakyow-go.
This is an unfortunate default config option in the currently released version. To get around it, add this to the production configuration block in app.rb:
app.static = true
The reason it works this way out of the box is in most production cases you don't want the app serving static files. This would instead be the responsibility of the HTTP server. On Heroku though, you want the app server to serve static files unless you host them from a CDN.

How do I use Heroku to host a personal website?

I want to use Heroku to host a website that has HTML, CSS and JS files, along with some jpegs and gifs.
I know how to do this with a Rails application, using;
heroku create --stack cedar
It seems that the cedar stack create a repo that is fit for Rails, Java ect apps because the error message is
Heroku push rejected, no Cedar-supported app detected
And when I try to launch the app it just say; Heroku | Welcome to your new app!
Here is a link: http://afternoon-brook-2543.herokuapp.com/
So I want to know how to put some JS, HTML, CSS and images files to host. Perhaps another command may create a simple website stack?
If you saved your root file as index.php then Heroku will detect it as a PHP application - it doesn't need to actually contain PHP code, just been named that.
If you want to send a personal website into Heroku, create an index.php file connected to your website. Launch the app as it was a PHP app. You will be able to launch the app with ease!
Hope this helped!

How do I create alias for Jekyll static site on Heroku?

I have a Jekyll site running on Heroku.
After site generation, I have a file created public/photos.html. How do I set up Jekyll/Heroku to allow me to access the page as domain.com/photos instead of domain.com/photos.html?
And I'd prefer NOT to have to use rack-rewrite which stands up rack middleware. Seems a bit much for this.
Thanks!
Simplest way is to just name the file photos/index.html instead of photos.html. If that doesn't work for you, you can use the variable permalink in the Front Matter.
You can do route matching in Sinatra and serve whatever pages you like, see: http://www.sinatrarb.com/intro.html

Simple "static" Ruby sites?

For early development, I typically build out a static version of the site. Previously I'd use PHP and have something like...
images
javascripts
stylesheets
templates
-- header.php
-- footer.php
index.php
users.php
And the index.php and users.php would have some basic PHP include code for those header and footer files.
I also got the added benefit of being able to use a few PHP functions.
But I haven't used PHP for anything in ages and use Ruby almost exclusively...so I'm wondering, is there a way to pull off something really basic like this in Ruby?
Primarily looking for something that allows me to:
Do basic file includes (so I can create simple templates)
Run Ruby inside the files
Ideally I could also use LiveReload with it.
Additional details: I'm running this locally on OS X and I typically use Pow as a server.
Peter is right to recommend Sinatra. There are typically two types of Sinatra applications. Modular and classical. For your example, I'll create a classical application. It isn't much work to convert it to a modular if you find that style would better fit your needs.
You'll want to install the gem with gem install sinatra. Create a new directory for your project and two new files as follows:
# app.rb
require 'sinatra'
get '/' do
erb :index
end
# config.ru
require './app'
run Sinatra::Application
Create another directory called views and add this file:
# index.erb
Hello World!
Then type ruby app.rb and viola, you now have a working project on localhost:4567/.
To serve static files like css and js, just create a public directory. From there, any file will be able to accessed after the root url. So if you created a css folder, its respective url would be: yourdomain.com/css/styles.css.
So the entire directory would be as folllows:
app/
app.rb
config.ru
public/
css/
js/
images/
views/
index.erb
Between the Sinatra Book and the read me, you should be able to find all the info you need.
To accomplish the templates, you'll need something called Sinatra Partial.
I'm not too familiar LiveReload but it seems like Compass accomplishes the same thing and has great integration with Sinatra. So long as pow is a rack based, you should have no problem using it.
Here is a Sinatra Bootstrap I use for all my projects. It has Compass and Sinatra Partial preconfigured and makes it really easy to deploy with Heroku. It also uses Slim, Coffeescript, Thin (as the server), Twitter Bootstrap and Sass but it shouldn't be too much work to sub that with your respective favorites or remove them all together.
I gifted my girlfriend a website with her domain name, I chose Jekyll for the job which uses RubyGems for the purpose.
It was easy and fun. Moreover you have lots of themes available which you can configure with .YML files just changing there will work for hole site. Although Linux or Mac OS is suggested by official Jekyll website but i did it in windows which was not much of a problem. They have steps defined for working on windows on their website.
http://jekyllrb.com/
The best part was that i could host the website via the git hub pages only. I didn't have to buy anything. Git hub allows you to host one repo. (funFact : Jekyll was developed by github inventor)
That's the one i used and made the website in 20 hours with no prior knowledge of Ruby and Jekyll.
So i will suggest you check it out!
Perhaps Jekyll will fit the bill?
Its description:
Jekyll is a simple, blog aware, static site generator. It takes a
template directory (representing the raw form of a website), runs it
through Textile or Markdown and Liquid converters, and spits out a
complete, static website suitable for serving with Apache or your
favorite web server. This is also the engine behind GitHub Pages,
which you can use to host your project’s page or blog right here from
GitHub
Yes, i use Sinatra for this, see https://github.com/sinatra/sinatra/ for some samples.
Running ruby inside the files isn't very static but in Sinatra you can do both.
Jekyll won't leave you run Ruby code "inside" the files. Jekyll is a parsing engine bundled as a ruby gem. You basically code templates using HTML and Liquid and write content using markdown that gets embebed generating plain HTML files that you can upload to any web server.

Resources