I have created two projects one the API Gateway that uses this JSON file:
{
"Routes": [
{
"DownstreamPathTemplate": "/api/post",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 44309
}
],
"UpstreamPathTemplate": "/gateway/post",
"UpstreamHttpMethod": [
"POST",
"PUT",
"GET"
]
}
]
}
And on the Microservice side the other project i have created a PostController that inherits Controllerbase, basically an ApiController:
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PostService.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PostService.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class PostController : ControllerBase
{
private readonly IPostRepository _postRepository;
public PostController(IPostRepository postRepository)
{
_postRepository = postRepository;
}
[HttpGet]
public IActionResult Get()
{
var posts = _postRepository.GetPosts();
return new OkObjectResult(posts);
}
}
}
When I run the project Two browsers open, the first which is the ApiGateway and the other browser is where the microservice runs on localhost on port 44309. I run this in the address bar for the api gateway:
https://localhost:44342/gateway/post
The great thing is that the Get Method in my PostController get called and returns the data correctly.
But if I wanted to run or deploy these projects on windows server, how would this work on a windows server. What would I need to change in my ocelot.json file or does this remain the same or do O need to change these values to the remote IP and port:
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 44309
}
],
So could someone point me in the right direction on how to deploy this on a windows server so that maybe a web or mobileapp can access the APIGateway?