404 Not Found: Angular 2 can't talk to Spring Rest API - spring

I followed Angular 2's Tour of Hero tutorial with in memory database. Then I created a Spring backend to supply data and want to integrate Angular2 with Spring's Rest API.
In Tour of Hero I only changed one line of code in hero.service.ts:
/* private heroesUrl = 'app/heroes'; */
private heroesUrl = 'http://localhost:8080/api/hero/all';
The link I changed to is the the Spring service endpoint, if I type the link in browser, it returns JSON data: [{"id":1,"name":"test"}].
However, I am getting error in Tour of Hero:
EXCEPTION: Uncaught (in promise): Response with status: 404 Not Found for URL: null
It looks like the spring endpoint of localhost:8080 is not found by Angular application running on localhost:3000. What could be the issue?

This was asked a while ago, but probably someone finds it useful.
Delete the following dependency from your package.json:
"angular-in-memory-web-api": "~0.2.4",
Remove it from node_modules directory, delete all InMemoryWebApiModule and InMemoryWebApiModule and InMemoryDataService-related code.

Related

facing error in paystack integrattion in laravel 8

Hi I'm trying to integrate paystack in laravel 8 but I'm click paynow button it give following error
Client error: POST https://api.paystack.co/transaction/initialize resulted in a 404 Not Found response:
{
"status": false,
"message": "Invalid Split code."
}
anyone can help how can i solve this
thanks
Can you share the request body? It looks like you're trying to pass a split code when you're initializing the transaction, but the code you're passing either:
Doesn't exist on that integration
Exists on the integration but maybe in test mode, and you're using your live keys (or in live mode and you're using your test keys)

django-rest-auth throws error with URL versioning

Using Django Rest Auth for authentication in my DRF based app. Issue is, the logout URL does not work when I add URL versioning.
Calling: /v1/rest-auth/logout/ (POST)
Throws error: TypeError: post() got an unexpected keyword argument 'version'
urls.py:
URL_VERSION = r'^(?P<version>v[1])'
url(f'{URL_VERSION}/rest-auth/', include('rest_auth.urls'))
Other end-points e.g. login via /v1/rest-auth/login/ works okay with and without the URL_VERSION.
What could I be missing?
This issue was fixed recently.
https://github.com/Tivix/django-rest-auth/pull/373
The new version will be on pypi very shortly. Please pull the master branch version for now if possible.

elmah.axd/stylesheet not found error

I Just installed ELMAH 1.2.2 from nuget to my WebApi 2 (5.2.3) project. It logs errors but elmah.axd's stylesheet doesn't load. And WebApi shows the following error:
{
"message": "No HTTP resource was found that matches the request URI 'http://api.sample.dev/elmah.axd/stylesheet'.",
"messageDetail": "No type was found that matches the controller named 'elmah.axd'."
}
I read some answers but doesn't seems related to my case.
I solved this error by preventing the WebApi's routing from catching requests to *.axd.
You can add the following line to your routing config.
httpConfig.Routes.IgnoreRoute("DynamicResources", "{resource}.axd/{*pathInfo}");
Now you can access elmah.axd's stylesheet and have a well styled log report page.

Cache internal routes with sw-precache

I'm creating a SPA using vanilla JavaScript and currently setting up sw-precache to handle the caching of resources. The service worker is generated as part of a gulp build and installed successfully. When I navigate to the root url (http://127.0.0.1:8080/) whilst offline the app shell displays, illustrating that resources are indeed cached.
I'm now attempting to get the SW to handle internal routing without failing. When navigating to http://127.0.0.1:8080/dashboard_index whilst offline I get the message 'Site can't be reached'.
The app handles this routing on the client side via a series of event listeners on the users actions or, in the case of using the back button, the url. When accessing one of these urls, no calls to the server should be made. As such, the service worker should allow these links to 'fall through' to the client side code.
I've tried a few things and expected this Q/A to solve the problem. I've included the current state of the generate-service-worker gulp task, and with this setup I'd expect to be able to access /dashboard_index offine. Once this is working I can adapt the solution to cover other routes.
Any help much appreciated.
gulp.task('generate-service-worker', function(callback) {
var rootDir = './public';
swPrecache.write(path.join(rootDir, 'sw.js'), {
staticFileGlobs: [rootDir + '/*/*.{js,html,png,jpg,gif,svg}',
rootDir + '/*.{js,html,png,jpg,gif,json}'],
stripPrefix: rootDir,
navigateFallback: '/',
navigateFallbackWhitelist: [/\/dashboard_index/],
runtimeCaching: [{
urlPattern: /^http:\/\/127\.0\.0\.1\:8080/getAllData, // Req returns all data the app needs
handler: 'networkFirst'
}],
verbose: true
}, callback);
});
update
The code to the application can be found here.
Removing the option navigateFallbackWhitelist does not chage the result.
Navigating to /dashboard_index whilst offline prints the following to the console.
GET http://127.0.0.1:8080/dashboard_index net::ERR_CONNECTION_REFUSED
sw.js:1 An unknown error occurred when fetching the script.
http://127.0.0.1:8080/sw.js Failed to load resource: net::ERR_CONNECTION_REFUSED
The same An unknown error occurred when fetching the script. is also duplicated in the 'application > service workers' tab of chrome debug tools.
It's also noted that the runtimeCaching option is not caching the json response returned from that route.
For the record, in case anyone else runs into this, I believe this answer from the comments should address the issue:
Can you switch from navigateFallback: '/' to navigateFallback:
'/index.html'? You don't have an entry for '/' in your list of
precached resources, but you do have an entry for '/index.html'.
There's some logic in place to automatically treat '/' and
'/index.html' as being equivalent, but that doesn't apply to what
navigateFallback is doing...

Bitbucket - Webhook keep returning error 500

Would like to check, I am fairly new to Bitbucket's new introduced webhook where previously i was using services where Bitbucket will execute a link to my site thus triggering a deployment script.
So since the old service is going to be depreciated soon, we all migrated to webhook instead. With the same implementation, I keep getting an error 500 upon commit/push/merge and there is no way for us to see the details for the error given. At first I thought it was my server giving problem but when i call the link manually via browsers and everything was fine. The deployment script can be executed successfully so then why bitbucket's webhook keeps telling me error 500?
Subsequently I find the guide given by Bitbucket was not helpful. There is no specified call method to the url stated so is the webhook initiates a GET or POST request? previously using services initiates a POST request. Then, are there any necessary payloads i need to include into the webhook URL? None is stated. Then, if there is an error at least let me see the error so I can fix it instead of telling me error 500.
I hope someone here can help me with this issue. Below are some specification of the site.
Server : Ubuntu LEMP 14.04 x64 Laravel framework 5.0
Webhook Url: bot.example.com/bitbucket/deploy/{Site API}
Method : GET
And when the abode link is call, it reaches a controller that does
public function attemptDeploy($site_api)
{
$script = 'nohup setsid php ~/scripts/deploy.php ' . $site_api. ' > /dev/null 2>&1 &';
exec($script);
return response('Deploy running.', 200);
}
Note that when i call this link manually either form browser or console everything works perfectly except from bitbucket's webhook. How can i solve this issue?
I was in the same situation. Bitbucket trims the body of the response and I couldn't see the error given by my server.
I've looked into the logs storage/logs/laravel.log and saw TokenMismatchException. Webhooks being API calls they don't store cookies or sessions so CSRF from Laravel breaks.
You need to add an exception from CSRF for the bitbucket deploy route. You can add this exception in app/Http/Middleware/VerifyCsrfToken.php. For example if your link is www.your_site.com/bit_deploy you will have:
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
class VerifyCsrfToken extends BaseVerifier
{
/**
* The URIs that should be excluded from CSRF verification.
*
* #var array
*/
protected $except = [
'bit_deploy'
];
}
Hope that this helps you ... as I've lost 3 hours on this.
PS: at the time of writing this answer, bitbucket webhooks performs POST calls (not GET)

Resources