IntelliJ can deploy HTML/JS code at localhost:63342 on the fly. I can see how the frontend behaves immediately.
Now I have a web application.
http://localhost:8080/frontend
http://localhost:8080/backend
The frontend will fetch data from its backend. Now I cannot start a real backend at localhost:63342. How can mock some ajax response at localhost:63342. Is there any magic plugin of IntelliJ can help?
My current solution is put all ajax call in an Angular service module and replace it with a mocked service module. I believe there must be some better solutions.
If you want to mock up some endpoints for you to test with I would suggest you use Mockjax. This will allow you to do exactly what you want and you won't have to run two separate apps to do so. I'm not familiar with IntelliJ, but Mockjax only has a dependency on jQuery and you should be able to easily set it up with any project that at least uses jQuery.
Related
I need to know how data returned from the Spring MVC REST controller attaches to html page and what the Spring configuration do we have to do this.
The browser just prints this data out without view and that's all.
I have some Spring configurations to do it but unfortunatelly it doesn't work.
First, you have to create a spring web-mvc application with a correct configuration that will run without errors. There are plenty of tutorials on how to do it. After that, if you wish to get json data using your rest controllers, the most popular way to do it is by using javascript and the JQuery library. Using them you can make ajax calls to your api. There are plenty of tutorials on how to achive this again. Finnaly, your data will be on the client side and you can manage them (render them in your html-dom etc) using javascript and JQuery again.
Im migrating my code to a core application.
So far so good. i got it all running, but there is one problem.
I had a ui (with razor) and using the CatchAllHandlers. And for the api i used HandlerFactoryPath to prefix the urls.
Now i have 2 problems:
It seems CatchAllHandlers isn't used?
Route is only processed if route starts with HandlerFactoryPath?
The second issue is fixable but how would i go around the first one?
Do i make my own middle-ware or does servicestack support other ways of doing this?
CatchAllHandlers are executed in .NET Core, it's also what ServiceStack's new MVC RazorFormat uses to process Content Pages.
Specifying a HandlerFactoryPath, e.g:
SetConfig(new HostConfig {
HandlerFactoryPath = "api"
});
Tells ServiceStack that you only want to listen to requests from the /api path info. All other requests are passed through ServiceStack who calls the next module in .NET Core pipeline as per .NET Core's convention when it's not configured to handle a route.
Not sure if it's relevant to your solution but in ServiceStack .NET Core you can register a ServiceStack Handler in .NET Core module pipeline so you could for instance return a /default.cshtml Content Razor Page for each request that's not handled by ServiceStack, by registering it after ServiceStack:
app.UseServiceStack(new AppHost());
app.Use(new RazorHandler("/default"));
I am total JS newbie working on a project build in Grail 2.4.4, a web-app. It's a working app, build by a developer whom is not available anymore.
To get it to work locally I had to upgrade it to Grails 3.2.0. I got it almost working in Netbeans. But I got stuck at getting the data from the MySQL database.
The Chrome inspector says:
angular.min.js GET http://localhost:8080/<app>/currency/allCurrencies 404 ()
The controllers are written in Restangular which call the above URL.
What am I missing?
Firstly, Restangular is an Angular library which simplifies and standardizes making calls to a REST backend (which in your case is a Grails app). So, Restangular does not directly retrieve data from your a database, it invokes a web service which (in some cases) may retrieve data from a database.
In your case, Restangular is attempting to retrieve data from the endpoint http://localhost:8080/<app>/currency/allCurrencies but you are getting a 404 response, indicating that there is no endpoint mapped to this URL.
HTTP REST helps you connect to the API easily. Restangular can handle that by sending standard methods [Get, Post, Delete, Put] to the api like what you see.
This mean StudentController > Get()
localhost:2045/api/student
This mean StudentController > Get(Guid id)
localhost:2045/api/student/8ae37cfa-905b-4c71-ad03-bf416d93bdf8
This mean StudentController > POST(Guid id) ... if you send Post method to the API, it will detect it, this work also on put method
localhost:2045/api/student
use this module to get easily rest api.
Http-Rest-Service
I'm trying to set up a basic component that is rendered on the server and the client. The component is populated with data from a JSON API. I've got this working on the client-side by loading my data in componentDidMount and calling this.setState when it has loaded.
The problem I have is that the data isn't loaded on the server. How do I get the initial data into the server-rendered version of my component?
https://github.com/rackt/react-router/blob/latest/docs/guides/advanced/ServerRendering.md is very vague about this:
For data loading, you can use the renderProps argument to build
whatever convention you want--like adding static load methods to your
route components, or putting data loading functions on the
routes--it's up to you.
Do you have an example anywhere of how to do this? It seems like a very basic thing for a universal application to want to do!
Yup - we have https://github.com/rackt/async-props that provides a library for dealing with async data between server and client, and provides an example for doing so. If you're using a Flux framework, you'll want to make appropriate adjustments, but the basic approach will be quite similar.
I am developing Couchbase views and using the console is limiting because the output lines are truncated and JavaScript errors are not displayed. Is there a convenient way to test views locally with an engine like Node.js?
Thanks!
What about couchnode?
https://github.com/couchbase/couchnode
https://github.com/couchbase/couchnode/blob/master/tests/08-views.js
Also since basically view query is HTTP request you can use any Web/HTTP/REST client or library for debugging. But apparently official SDK seems to be more convenient way.
Also,
If you use the couchbase mock() function with the nodejs SDK, when you do your unit tests, the errors and console.log() inside your views are displayed.