Rails server error not clear - ruby-on-rails

Using OS X Sierra
I have a rails app with two parts: front-end and back-end.
On back-end I am using rails 4.
On the front-end I am using Angular.
Whenever I have to start the server locally (for development or test) I use 3 distinct console windows.
one to run grunt watch"
another to run http-server ./build/ -p 8000 -c-1
and the last to run rails server
My local backend repository is just a clone of what is running on production.(minus server configuration)
When I use the fronted connected to my remote server it works without problems. However, when I run the backend locally and try to log in, all I get is the following log, and no responses:
=> Booting WEBrick
=> Rails 4.2.7 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2017-01-02 16:19:21] INFO WEBrick 1.3.1
[2017-01-02 16:19:21] INFO ruby 2.3.3 (2016-11-21) [x86_64-darwin15]
[2017-01-02 16:19:21] INFO WEBrick::HTTPServer#start: pid=10496 port=3000
The front end throws the following error:
XMLHttpRequest cannot load localhost:3000/auth_user?
email=admin#railsapp.com&password=VVVVVVVV. Cross origin requests are
only supported for HTTP.
My Angular endpoint file
angular.module( 'common.config', [] )
.factory('endpoints', function() {
var host = 'development';
if (['live.companysite.com'].indexOf(window.location.host) > -1) {
host = 'production';
} else if (['companysite.com'].indexOf(window.location.host) > -1) {
host = 'development';
} else {
host = 'local';
}
var endpoints = {
'production': {
root: 'http://live.companysite.com/'
},
'development': {
root: 'http://companysite.com/'
},
'local': {
root: 'localhost:3000/'
}
};
return endpoints[host];
});
I know that it should be a CORS problem, but as it works perfectly with two remote servers (production and test) I believe that my local configuration might be the problem.

'localhost:3000auth_user?emai' I think you are missing an '/' before auth_user and after :3000, check the line where you define the api in your angular project, probably you need to add a slash .
Check changing this in your config:
'local': { root: "http:// localhost:3000/" }

Related

Why is the main.dart configuration getting ignored in my Dart Aqueduct server

My main.dart file for my Aqueduct server is
import 'package:dart_server/dart_server.dart';
Future main() async {
final app = Application<DartServerChannel>()
..options.configurationFilePath = "config.yaml"
..options.port = 3000; // changed from 8888
final count = Platform.numberOfProcessors ~/ 2;
await app.start(numberOfInstances: 1); // changed from count > 0 ? count : 1
print("Application started on port: ${app.options.port}.");
print("Use Ctrl-C (SIGINT) to stop running the application.");
}
I changed the port number and the number of instances, but when I start the server with
aqueduct serve
I still get port 8888 and two instances:
-- Aqueduct CLI Version: 3.1.0+1
-- Aqueduct project version: 3.1.0+1
-- Preparing...
-- Starting application 'dart_server/dart_server'
Channel: DartServerChannel
Config: /Users/jonathan/Documents/Programming/Tutorials/Flutter/backend/backend_app/dart_server/config.yaml
Port: 8888
[INFO] aqueduct: Server aqueduct/1 started.
[INFO] aqueduct: Server aqueduct/2 started.
Only if I explicitly start the server like this
aqueduct serve --port 3000 --isolates 1
do I get port 3000 and one instance:
-- Aqueduct CLI Version: 3.1.0+1
-- Aqueduct project version: 3.1.0+1
-- Preparing...
-- Starting application 'dart_server/dart_server'
Channel: DartServerChannel
Config: /Users/jonathan/Documents/Programming/Tutorials/Flutter/backend/backend_app/dart_server/config.yaml
Port: 3000
[INFO] aqueduct: Server aqueduct/1 started.
Why didn't changing main.dart affect it? (I saved the file after making changes.) Is there somewhere else that I need to make the update?
I don't find it in any documentation but it seems that when you run "aqueduct serve" command, the bin/main.dart file isn't executed.
The aqueduct serve command uses its own configuration on command line. You need to specify the port using the -port option.
If you want to use your main.dart file you can also execute the server directly using
dart bin/main.dart
in your project folder.

Ember CLI and Rails: Error proxying to http://localhost:3000

I am following this tutorial for Ember CLI and Rails. I am stuck at the point where you are supposed to load the Book model data using the following command in the console:
App.store.findAll('book');
No data is retrieved and the Ember terminal logs show this error:
Error proxying to http://localhost:3000
connect ECONNREFUSED 127.0.0.1:3000
Error: connect ECONNREFUSED 127.0.0.1:3000
at Object.exports._errnoException (util.js:890:11)
at exports._exceptionWithHostPort (util.js:913:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1061:14)
GET /books - - ms - -
However when I visit http://localhost:3000/books (the Rails backend), I get the correct JSON response with all the books. Why is the Ember app not able to retrieve this data and how can I fix it?
Restart the Rails server with:
rails s --binding 0.0.0.0
then restart the ember server.
There are multiple things you need to watch.
Try setting up in your embers config/environment.js for each environment proper URL and settings. More info here.
ENV.contentSecurityPolicy = {
'default-src': "'none'",
'script-src': "'self'",
'font-src': "'self'",
'connect-src': "'self' http://localhost:3000",
'img-src': "'self' data:",
'style-src': "'self' 'unsafe-inline'",
'media-src': "'self'"
};
And you also need to explain Rails app to accept connection outside of the rails app. CORS. Looks for this gem.

Server not available on localhost with response code 403 & RuntimeError in Ruby on Rails

After changing proxy settings in open_uri.rb and server_manage.rb I finally managed to install neo4j behind a proxy server. The neo4j server is running on port 7000 ( It opens in the browser) but when i enter :
$rails generate scaffold post title body
Error:
/.rvm/gems/ruby-2.2.3/gems/neo4j-core-5.1.6/lib/neo4j-server/cypher_session.rb:51:in `open': Server not available on http://localhost:7000 (response code 403) (RuntimeError)
What should I do ?
Any help is appreciated!!
$ ruby --version
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
$ rails --version
Rails 4.2.2
My guess - proxy issues. Things may behave differently in your browser and code (because those are 2 different environment).
To check what exactly is going on with your database, you should try to make request to Neo4j manually, from command line.
Example with using curl:
# if auth enabled
curl -i --user username:password http://localhost:7000/db/data/
# if auth disabled
curl -i http://localhost:7000/db/data/
This will give you more details on what exactly is not working.
Also you can assemble basic ruby script that will make HTTP request, to check what you receive in response in this case.
A 403 might mean that your Neo4j authentication credentials are wrong. See http://neo4jrb.readthedocs.org/en/5.1.x/Setup.html#rails-configuration for details but basically, adding something like this to application.rb might do the trick:
config.neo4j.session_options = { basic_auth: { username: 'foo', password: 'bar'} }
Also, since you mentioned needing help with the proxy, you can add an initialize key to set that.
init = { proxy: { uri: 'http://myproxy', user: 'username', password: 'password' }}
auth = { username: 'neo4j', password: 'pwhere'}
config.neo4j.session_options = { basic_auth: auth, initialize: init }

Neo4j - How to set DEV ENV to point to an AWS database

I created a new app in Rails using:
rails new myapp -m http://neo4jrb.io/neo4j/neo4j.rb -O
I did not executed the command:
rake neo4j:install[community-2.2.0,development]
since my database is already created, populated and hosted by an AWS server.
How I can set my Rails dev env to use the database on the AWS server?
When running the command from my local computer myapp folder
$ rails s -d
I am getting the error:
Expected response code 200 Error for request http://my-aws-server.com:7474/db/data/, 401, 401 (Neo4j::Server::Resource::ServerException)
I added these three lines in the file config/environments/development.rb:
config.neo4j.session_options = { basic_auth: { username: 'neo4j_user', password: 'neo4j_pass'} }
config.neo4j.session_type = :server_db
config.neo4j.session_path = 'http://my-aws-server.com:7474'
Problem solved.

grails + selenium-rc plugin - cannot run sample test

I have no idea what I do wrong. I would like to use selenium-RC plugin for Grails to do some functional testing. I have created sample test using build-in script (i guess add-selenium-test), which generated (i modified it slighty):
import grails.plugins.selenium.*
import org.junit.*
import static org.junit.Assert.*
import static org.hamcrest.Matchers.*
#Mixin(SeleniumAware)
class FirstTestTests {
#Before void setUp() {
}
#After void tearDown() {
super.tearDown()
}
#Test void something() {
selenium.open "/activate"
assertTrue selenium.isTextPresent("activate")
}
}
I configured SeleniumConfig
selenium {
slow = false // true to run tests in slow resources mode
singleWindow = true // true for single window mode, false for multi-window mode
browser = "*firefox" // can include full path to executable, default value is *firefox or *iexplore on Windows
url = "http://localhost:8080" // the base URL for tests, defaults to Grails server url
defaultTimeout = 3000 // the timeout after which selenium commands will fail
windowMaximize = true // true to maximize browser on startup
screenshot {
dir = "./target/test-reports/screenshots" // directory where screenshots are placed relative to project root
onFail = true // true to capture screenshots on test failures
}
server {
host = "localhost" // the host the selenium server will run on
port = 4444 // the port the selenium server will run on
}
userExtensions = "" // path to user extensions javascript file
}
and I then I typed
grails test-app :selenium
and it seems that everything is done correctly:
INFO 19:30:08,304 RemoteWebDriver instances should connect to: http://127.0.0.1:
4444/wd/hub org.openqa.selenium.server.SeleniumServer
Starting Selenium server on port 4444 ...
INFO 19:30:08,312 Version Jetty/5.1.x org.openqa.jetty.http.HttpServer
INFO 19:30:08,315 Started HttpContext[/selenium-server/driver,/selenium-server/d
river] org.openqa.jetty.util.Container
INFO 19:30:08,318 Started HttpContext[/selenium-server,/selenium-server] org.ope
nqa.jetty.util.Container
INFO 19:30:08,321 Started HttpContext[/,/] org.openqa.jetty.util.Container
INFO 19:30:08,326 Started org.openqa.jetty.jetty.servlet.ServletHandler#55881a8f
org.openqa.jetty.util.Container
INFO 19:30:08,328 Started HttpContext[/wd,/wd] org.openqa.jetty.util.Container
INFO 19:30:08,338 Started SocketListener on 0.0.0.0:4444 org.openqa.jetty.http.S
ocketListener
INFO 19:30:08,340 Started org.openqa.jetty.jetty.Server#42aefb01 org.openqa.jett
y.util.Container
Starting Selenium session for http://localhost:8080 ...
INFO 19:30:08,502 Checking Resource aliases org.openqa.jetty.util.Credential
INFO 19:30:08,510 Command request: getNewBrowserSession[*firefox, http://localho
st:8080, ] on session null org.openqa.selenium.server.SeleniumDriverResourceHand
ler
INFO 19:30:08,512 creating new remote session org.openqa.selenium.server.Browser
SessionFactory
INFO 19:30:08,586 Allocated session 9250557308cc4886a25100eb6c5f3d7e for http://
localhost:8080, launching... org.openqa.selenium.server.BrowserSessionFactory
INFO 19:30:08,717 Preparing Firefox profile... org.openqa.selenium.server.browse
rlaunchers.FirefoxChromeLauncher
INFO 19:30:11,726 Launching Firefox... org.openqa.selenium.server.browserlaunche
rs.FirefoxChromeLauncher
The firefox window is opened, but nothing loads and nothing seems to proceed. Do I miss something?
Sounds to me like an incompatibility between the Selenium RC plugin and the current version of your web browser. You might want to dig into the plugin's dependencies and update everything to the latest versions if you're using a newer version of the browser.
We see this with Geb ( http://www.gebish.org ) when trying to run a webdriver version that is not compatible with the driver version.
Just to add, if you use Chrome and your OS is Ubuntu, then make sure you put the full path to Chrome and make sure that the executable path references chromium-browser and NOT google-chrome.
So your SeleniumConfig should look like this with the relevant line in double asterisks:
selenium {
slow = false
singleWindow = true
**browser = "*googlechrome /usr/bin/chromium-browser"**
url = null
defaultTimeout = 60000
windowMaximize = false
screenshot {
dir = "./target/test-reports/screenshots"
onFail = false
}
server {
host = "localhost"
port = 4444
}
userExtensions = ""
}

Resources