How to configure Sinatra classic to use Puma - sinatra

I have an old project with classic Sinatra (not modular < Sinatra::Base). How can I make it use the Puma web server instead of Thin?
The only examples on the internet I could find using Puma were with modular Sinatra.
reference: http://www.sinatrarb.com/intro.html#Modular%20vs.%20Classic%20Style

Or if you just want use rakeup you can add to your config.ru
#\ -s puma
require './yourapp'
run Sinatra::Application

Just create config.ru:
require './yourapp'
run Sinatra::Application
then run:
puma

Related

Deploy and run a Go API server on Ubuntu/Centos

I just finished my first backend with Go using Iris framework but now I need to put it on production so I can use it in the Slack app I built.
In order to test the code locally I only run my file with go run main.go and ngrok to test with the Slack API, it's working and it's finished.
I have a droplet with Ubuntu 16.04.3 and other one with Centos 7... I was searching for something like pm2 for go, running the server and using nginx to point that port but I read that with Go it's different and I have to use something like this https://fabianlee.org/2017/05/21/golang-running-a-go-binary-as-a-systemd-service-on-ubuntu-16-04/
But that's a very long configuration for a simple server and my questions are:
Is this the usual way to config the APIs with Go?
Apart of DigitalOcean, do you recommend to use a different service to run my API?
This is really my first time with Go and I just want to learn more, I am a backend developer with Laravel and NodeJS.
You can use pm2 if you want. When you build a go project it creates a binary executable, lets say backend-server, which you can run from terminal and will start the app like this:
$ ./backend-server
If it's not executable or has permission denied issue, add the executable permission to it.
$ chmod +x backend-server
You binary should be ready to run. I like to do it with a json config file (process.json) so that I can pass extra env variables as well and don't have to type a lot in terminal.
My process.json looks something like this:
{
"apps" : [{
"name" : "backend-app",
"script" : "./backend-server",
"env": {
"DB_USER": "db_user",
"PORT": 8080
}
}]
}
Finally you can start the app using pm2 like this:
$ pm2 start process.json
More details about json config can be found in official doc
I think most people use Supervisor for this purpose, including me.
To make it very easy for you, just take a look at my Golang project, isaac-racing-server and use it as a template for yours by replacing isaac-racing-server with the name of your app. (The Supervisor files are in a subdirectory.)

How to use fastlane behind proxy

I can't find any option about fastlane to set the proxy. So does there has a direct way to solve this?
Thanks very much for any help!
I had the same problem and for me this site helped as fastlane is using Faraday internally. You have to set up the proxy environment variables for faraday with the following commands:
$ export http_proxy="http://proxy_host:proxy_port"
$ export https_proxy="https://proxy_host:proxy_port"
Any of the Fastlane tools that use spaceship (i.e. the Apple APIs) can be proxied using a combination of three environment variables.
SPACESHIP_PROXY: set the http proxy to use (SPACESHIP_PROXY =https://localhost:9090)
SPACESHIP_PROXY_SSL_VERIFY_NONE: when present, disables SSL verification (to allow inspecting HTTPS requests)
SPACESHIP_DEBUG: equivalent to SPACESHIP_PROXY=https://127.0.0.1:8888 SPACESHIP_PROXY_SSL_VERIFY_NONE=1, preconfigured for Charles Proxy defaults.
To use these, set them as environment variables in your shell, or prepend them to any fastlane command. For example, SPACESHIP_PROXY=https://localhost:9090 bundle exec fastlane
Source: Spaceship debugging documentation

How does sinatra start the server?

I have been trying to delve into how sinatra works, and most recently I've been trying to figure out how sinatra starts the server after processing the routes, when it is required at the top of the file. I was looking at this tutorial and they end with an example app looking like this (their version of sinatra is called nancy):
# app.rb
# run with `ruby app.rb`
require "./nancy"
get "/" do
"Hey there!"
end
Rack::Handler::WEBrick.run Nancy::Application, Port: 9292
I am wondering how you are not forced to include that last line in sinatra.
Sinatra does that by defining an at_exit callback, see main.rb
This basically says "when the ruby script is done and exits, then run the Sinatra app!"
For more information see the ruby docs for at_exit!
For serving a sinatra application you just need to execute ruby app.rb on shell.
app.rb
# install sinatra gem before everything
# by typing `gem install sinatra`
# on shell. or add sinatra to your Gemfile
# then execute bundle install
require 'sinatra'
get '/' do
"Hey there"
end
Then you'll see such output
$ ruby app.rb
Puma 2.11.3 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:4567
== Sinatra (v1.4.7) has taken the stage on 4567 for development with backup from Puma
The tutorial you've been appealing at is not about the actual sinatra - there author have built his/her own pseudo-sinatra. By the way, ruby also have a microframework called nancy
To run his/her pseudo-sinatra successfully, you need to follow the tutorial from beggining to end.

How do I not start sinatra when Gemfile refers to it?

all, I have a client application which is a sinatra app, but that's only part of it, some other parts will do related work like download so need to spawn in a new process, this is mostly required the gem dependencies of the same client project, so I of course using some code to load in the bundler environment:
Dir.chdir(File.expand_path(File.dirname(__FILE__)))
ENV["BUNDLE_GEMFILE"] = File.expand_path("../Gemfile", __FILE__)
require 'bundler'
env = ENV['RACK_ENV'] || 'development'
Bundler.setup
Bundler.require :default, env.to_sym,
but unfornately even with no code,like
puts 3,the sinatra app will starts and listens on 4567 which is quite irritating,
I also tried modular approach to write in the file an empty class
class MyApp < Sinatra::Base;
end
but still sinatra starts on 4567, which is
quite irritating,
do I have a way not to start sinatra? Thanks.
Find out the problem,
because in Gemfile, is:
gem "sinatra",
better use
gem "sinatra", :require =>"sinatra/base"
instead.

How to deploy bugzilla with psgi on dotcloud?

I want to deploy bugzilla on dotcloud, but the perl environment is psgi.
The doc said I must use "modules to add PSGI hooks to legacy CGI or FastCGI applications".
I found CGI::Emulate::PSGI module but could not figure out how to do it.
I am a Python programmer and have no experience in Perl.
I had partial success with bugzilla-4.0.2 on a local openSUSE. I don't think Bugzilla will be suitable for cloud deployment in the short term because of its large amount of manual setup necessary. Follow the instructions referenced from docs/en/html/index.html, then run
plackup -MPlack::App::CGIBin -e'Plack::App::CGIBin->new(root => ".")->to_app'
and visit http://localhost:5000/index.cgi. The static files are missing, e.g. stylesheets. Something like along the lines of
plackup -MPlack::Builder -MPlack::App::Directory -MPlack::App::CGIBin -e 'builder {
mount "/" => Plack::App::CGIBin->new(root => ".")->to_app;
mount "/" => Plack::App::Directory->new({ root => "." })->to_app;
}'
is necessary, but mounting to the same path actually does not work in Plack 0.9985, or I'm doing it wrong.
I did not try it but This sounds like what you want. Its bugzila deployed to a cloud stackato.
You can join Stackato then deploy the bugzilla sample.
https://github.com/Stackato-Apps/bugzilla