rails angular js subdomain - angularjs

I am new to angular js and I want request the server which is already implemented with subdomain for api part . I am facing issues when I want request the server api part from angular js . I tried like the following
1st case:
#service = $resource('/api.lvh.me/properties/:property_id/rates/:id',{})
2nd case:
#service = $resource('/api.lvh.me/properties/:property_id/rates/:id.json',{})
3rd case:
#service = $resource('http://api.lvh.me:3000/properties/:property_id/rates/:id.json',{})
no one is working for me , but when I tried the following its working fine
#service = $resource('/properties/:property_id/rates/:id.json',{})
In this case its hitting the normal controllers(not the api part/controllers) and I had to manage json type requests and rendering data accordingly , but I dont recommend this as I have already built the api part with sub domain constraint in rails , I want to go with this .
my routes defined like the following
namespace :api, defaults: {format: 'json'} , :path => '' , :constraints => {:subdomain => 'api'} do
....
end
Can anyone please help how to request the api part on the server .
Thanks ,

finally I fixed it by using rack-cors gem , I configured middileware as they suggested in application.rb file and changed my routing way like the following
$resource('http://api.lvh.me:3000/properties/:property_id/rates/:id',{})
Hope it helps for someone.

Related

How to configure asp.net core to return react front end and work with react-router?

I would like my backend to serve up my front end (which is written in react). I added the following cade to program.cs:
var frontEndBuildDirectory = "Path to front end build directory";
app.UseFileServer(new FileServerOptions()
{
FileProvider = new PhysicalFileProvider(frontEndBuildDirectory ),
RequestPath = ""
});
My understanding is that this code does two things:
If a request's url starts with the host name of my backend (localhost:xyzw), everything following the host name will be a virtual path into frontEndBuildDirectory.
When a request is made into frontEndBuildDirectory (the directory itself, not a file within the directory), then the response is the index.html file within frontEndBuildDirectory.
The problem is that my react code uses the react-router library. If I make a request to the backend (localhost:xyzw), the front end is served. Then when I click on something that changes the route (using react router), the url changes to localhost:xyzw/route1 and the everything works. However, if I try to search up localhost:xyzw/route1, I get a page not found error.
My understanding is that this happens because there is no file named route1 in frontEndBuildDirectory.
What is the proper way to make requests like localhost:xyzw/route1 not give a page not found error?

App Engine Backend Server Address (Insecure response)

I'm following this tutorial https://cloud.google.com/appengine/docs/standard/python/authenticating-users-firebase-appengine
At the end it says:
Change the backend host URL in main.js to https://backend-dot-[PROJECT_ID].appspot.com. Replace [PROJECT_ID] with your project ID.
As an example my project ID is "project", does this mean I should set the URL to:
https://backend-dot-project.appspot.com
OR
https://backend.project.appspot.com
I've tried setting it to both, and I get an INSECURE_RESPONSE error in Chrome. I don't know what URL I need.
Can anyone help me?

Cakephp - Custom authentification (basicauth) in a plugin

I am currently developing an Restfull API for my website.
I decided to develop it as a plugin.
I am using a custom class that extends BasicAuthentification. It allows me to check the client-app credential, in order to limit the API use to only approved developers.
This file works perfectly when added in the CakePHP CORE : Cake/Controller/Component/Auth/DeviceAuthentification.php
Since I am developing a Plugin, I would like everything to be inside the same directory.
Therefore in my plugin directory called MyApi, I added my custom class in the following path :
MyApi/Controller/Auth/DeviceAuthentification.php
In order to load it, in my Plugin's controller MyApiAppController, I added the following code :
public $components = array(
'Auth' => array(
'authenticate' => 'Device', // I also tried MyApi.Device
'sessionKey' => false
)
);
It does not load, the error is the following :
Authentication adapter "Device" was not found.
Anybody has an idea ?
Well, after having a look in the core file AuthComponent, it seems that you need to have the following path :
MyApi/Controller/Component/Auth/DeviceAuthentification.php
instead of
MyApi/Controller/Auth/DeviceAuthentification.php
Therefore, whenever you are working in the Plugin directory, you need to add the directory Component

Hosting nancy with asp.net on IIS 6 - failed - wrong configuration

I tried some stuff to host a little nancy test api under IIS 6:
https://github.com/NancyFx/Nancy/wiki/Hosting-nancy-with-asp.net
http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx
But it dont work. Here are my steps:
Create Empty Nancy Web Application
Add Reference with nuget - Nancy.Hosting.Aspnet Version 0.15.1
new Web.config is modifyed automatically
as described in the wiki
Add new class in solution root - HelloModule.cs
insert test code "HelloWorld"
Publish the web site local
on Windows 2003
with a virtual Directory in the IIS manager
Browsing the url 'localhost/nancyTest' brings an HTTP 403 ERROR.
A little ASP.NET WebApplication runs with the same configuration.
The nancyTest application does not have a start site like default.aspx. I want to get the request response from .../nancyTest/ coded as:
public class HelloModule : NancyModule
{
public HelloModule()
{
Get["/"] = parameters => "Hello World";
}
}
Perhaps the call .../nancyTest/ is not a GET Request? Are there other things to go in more detail?
I know not so many people user IIS6 nowadays, but there is the following solution, i wish it can help some people that still use this old one,
Config aspnet_isapi to handle a new ext files and like , .start
Set default page for this application is index.start
In nancy module add the redirect method, like the follwing:
Get["index.start"] = _ => {
return Response.AsRedirect("~/", Nancy.Responses.RedirectResponse.RedirectType.Permanent);
};
wish it helps

Backbone routes break on refresh with Yeoman

I am building an app with Backbone and Yeoman. I am having an issue with the routing.
I have the following routes set up:
'test' : testMethod,
'' : index
I have set up pushstate:
Backbone.history.start({pushState: true});
I am using Chrome
If enter myApp.com#test the url changes to myApp.com/test and testMethod() fires correctly.
However if I try goto myApp.com/test directly or refresh after the browser has changed the url from # to / then I get a 404.
I am using the Yeoman built in server to test the pages. Could this be causing the issue?
I am not sure if you are using BBB within Yeoman. If you are, this should not be an issue. If you are not using BBB, this is a known issue. BBB has it's rewrite rules setup correctly to use pushstate, but yeoman's built in server does not seem to adopt this. You could edit your grunt.js file with your own rewrite rules to get pushstate working correctly. Some of the users in the above mentioned link have done this successfully.
When your app goes live, you will either need to serve those urls through your server or edit your rewrite rules to do the same. If the latter, and your application relies on SEO, SEO will suffer greatly.

Resources