How to delete route to a particular node in the agent? - unetstack

I want to delete routing entries from routing table to a node 1 from the agent but i am not able to figure out how to write code for deleting routing entries to a particular node through my own agent.

What you're looking for is the EditRouteReq in the ROUTING service of UnetStack. The EditRoutReq has constructors that allow deletion of route that match specific criteria (e.g. EditRouteReq.deleteRoute() or EditRouteReq.deleteRoute(String uuid)). Sending this request to the router (agent offering the ROUTING service should do what you want.
Example code snippet to delete route with UUID id:
r = EditRouteReq.deleteRoute(id)
r.recipient = agentForService(Services.ROUTING)
request(r, 1000)
or to delete all routes to destination address addr:
r = EditRouteReq.deleteRoute()
r.to = addr
r.recipient = agentForService(Services.ROUTING)
request(r, 1000)

Related

How to remove a route in the groovy code without using a agent in unetstack?

As with unetstack shell we can delete a route but how to delete a route in the groovy code without using the Agent
Refer to the documentation for Routing service in the Unet handbook for how to do this. Essentially you need to send a EditRouteReq created using the deleteRoute() constructor method, and send it to the agent providing the ROUTING service.
For example, if you want to delete all routes to node 10, this will look something like:
def router = agentForService(Services.ROUTING)
def req = EditRouteReq.deleteRoute()
req.to = 10
def rsp = router << req
// rsp will have performative AGREE if the request was successful

Undertow ResourceHandler to return the same file when a path cannot be found

I am using undertow to statically serve a react single page application. For client side routing to work correctly, I need to return the same index file for routes which do not exist on the server. (For a better explanation of the problem click here.)
It's currently implemented with the following ResourceHandler:
ResourceHandler(resourceManager, { exchange ->
val handler = FileErrorPageHandler({ _: HttpServerExchange -> }, Paths.get(config.publicResourcePath + "/index.html"), arrayOf(OK))
handler.handleRequest(exchange)
}).setDirectoryListingEnabled(false)
It works, but it's hacky. I feel there must be a more elegant way of achieving this?
I could not find what I needed in the undertow documentation and had to play with it to come to a solution. This solution is for an embedded web server since that is what I was seeking. I was trying to do this for an Angular 2+ single page application with routing. This is what I arrived at:
masterPathHandler.addPrefixPath( "/MY_PREFIX_PATH_", myCustomServiceHandler )
.addPrefixPath( "/MY_PREFIX_PATH",
new ResourceHandler( new FileResourceManager( new File( rootDirectory+"/MY_PREFIX_PATH" ), 4096, true, "/" ),
new FileErrorPageHandler( Paths.get( rootDirectory+"/MY_PREFIX_PATH/index.html" ) , StatusCodes.NOT_FOUND ) ) );
Here is what it does:
the 'myCustomServiceHandler' provides the handler for server side logic to process queries sent to the server
the 'ResourceManager/FileResourceManager' delivers the files that are located in the (Angular) root path for the application
The 'FileErrorPageHandler' serves up the 'index.html' page of the application in the event that the query is to a client side route path instead of a real file. It also serves up this file in the event of a bad file request.
Note the underscore '_' after the first 'MY_PREFIX_PATH'. I wanted to have the application API URL the same as the web path, but without extra logic, I settled on the underscore instead.
I check the MIME type for null and serve index.html in such a case as follows:
.setHandler(exchange -> {
ResourceManager manager = new PathResourceManager(Paths.get(args[2]));
Resource resource = manager.getResource(exchange.getRelativePath());
if(null == resource.getContentType(MimeMappings.DEFAULT))
resource = manager.getResource("/index.html");
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, resource.getContentType(MimeMappings.DEFAULT));
resource.serve(exchange.getResponseSender(), exchange, IoCallback.END_EXCHANGE);
})

Multiple GET routes with different parameters

does anyone know if u can and if its good practice to define multiple GET routes such as:
GET: '/channels' returns all channels in the app
GET: '/channels/:username' returns all channels created by a user
GET: '/channels/:channelname' return details about a channel
POST: '/channels' creates a new channel
PUT: '/channels/:channelname' edits a channel with the name ':channelname'
What im confused is the third GET route. Don't know if it's possible or if theres a better way to do it..
You cannot have multiple routes with the same parameter.
I think that the most logical way is to do this :
GET: '/channels/user/:username' returns all channels created by a user
You couldn't use same verb (get, post, put ..) for same route. You can use same verb for different route or same route for different verb.
in your problem used
GET: '/channels/:username' and
GET: '/channels/:channelname'
both act as a same thing because when you request by /channels/somename fro client site then valid for both routes because username can be somename or channelname can be somename.
so to differentiate two routes need to change your any one route. like
GET: '/channels/user/:username' // that different from /channels/:channelname
for node.js and express you can use like:
var router = express.Router();
router.route('/place')
.get(placeController.getPlaces)
.post(placeController.createPlace);
router.route('/place/:placeId') // same route for different verb
.get(placeController.getPlaceById)
.put(placeController.updatePlaceById)
.delete(placeController.deletePlaceById);
router.route('/hotel/:placeId') // here :placeId params name same for both but /hotel differentiate from /place
.get(hotelController.getHotelById)
.put(hotelController.updateHotelById)
.delete(hotelController.deletHotelById);

Subdomain in react router

I'd like to setup react router for use with subdomains. I'm unsure where the logic for subdomain proxying should lie.
I want:
roxy.coolestblog.com/profile to route to coolestblog.com/roxy/profile
mohammed.coolestblog.com/profile to route to coolestblog.com/mohammed/profile
benben.coolestblog.com/profile to route to coolestblog.com/benben/profile
another use case:
en.coolestblog.com/some-article to route to coolestblog.com/en/some-article
fr.coolestblog.com/un-article to route to coolestblog.com/fr/un-article
es.coolestblog.com/una-article to route to coolestblog.com/es/una-article
I already have it working without the subdomain.
How can I achieve this so it works both on client and server?
While the browser history API limits our ability, we can interact directly with window.location in order to accomplish this.
Just before setting up your router, you can modify the URL by doing something like this:
let host = window.location.host;
let protocol = window.location.protocol;
let parts = host.split(".");
let subdomain = "";
// If we get more than 3 parts, then we have a subdomain
// INFO: This could be 4, if you have a co.uk TLD or something like that.
if (parts.length >= 3) {
subdomain = parts[0];
// Remove the subdomain from the parts list
parts.splice(0, 1);
// Set the location to the new url
window.location = protocol + "//" + parts.join(".") + "/" + subdomain;
}
Of course, this has its caveats. For instance, if you do not know your host name explicitly, you cannot correctly determine if there is a subdomain or not. It does not make any assumptions about what the following URL should be, but it would be trivial to solve for that.

Delphi EMS FireDAC: How to pass parameter from client to server using EMS?

I am working on the simple client server application using EMS (i.e: for future iOS application) in Delphi.
On the client unit, I have EMSProvider and EMSFireDACClient which fetches data from a Database (MSSQL) through a Datasource.
On the server unit, I have FDConnection and TFDQuery which deals with my Database. So far everything is working fine.
Question: Now I need to pass some parameters from client to the server and that fetches the result data. How should I do using EMS? Any functions or procedures available in EMS?
Regarding source code, everything was handled by corresponding components. So coding part is very less.
Thanks in advance.
An EMS call is like a REST call. You can pass further URL parameters both in the path (handled directly) -- see the default implementation of getting items by ID) and as extra query params. Those are in the request object. To pass them, use a custom Endpoint in the client.
Here is some more info:
Server declaration:
[ResourceSuffix('{item}')]
procedure GetItem(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse);
Server implementation:
procedure TNotesResource1.GetItem(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse);
var
LItem: string;
begin
LItem := ARequest.Params.Values['item'];
...
Client configuration for endpoint:
object BackendEndpointGetNote: TBackendEndpoint
Provider = EMSProvider1
Auth = BackendAuth1
Params = <
item
Kind = pkURLSEGMENT
name = 'item'
Options = [poAutoCreated]
end>
Resource = 'Notes'
ResourceSuffix = '{item}'
end
Client call:
BackendEndpointGetNote.Params.Items[0].Value := AID;
BackendEndpointGetNote.Execute;
Hope this helps.

Resources