As per the documentation i tried to merge my config files so they are a bit more readable. The generated ocelot.json file however is not like expected. My folder structure is like follows:
Folder structure
Below is a text representation of this:
.
└── Ocelot route configs
├── ocelot.pokemon.json
├── ocelot.tweet.json
└── ocelot.weather.json
The ocelot.pokemon.json file looks like following (the others are similar to this):
{
"Routes": [
{
"DownstreamPathTemplate": "/api/v2/pokemon",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "pokeapi.co",
"Port": 443
}
],
"UpstreamPathTemplate": "/api/pokemon",
"UpstreamHttpMethod": [ "GET" ],
"AuthenticationOptions": {
"AuthenticationProviderKey": "MyTestKey",
"AllowedScopes": []
}
},
{
"DownstreamPathTemplate": "/api/v2/pokemon/ditto",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "pokeapi.co",
"Port": 443
}
],
"UpstreamPathTemplate": "/api/pokemon/ditto",
"UpstreamHttpMethod": [ "GET" ]
}
]
}
The generated ocelot.json file looks like this:
{
"Routes": [
],
"DynamicRoutes": [
],
"Aggregates": [
],
"GlobalConfiguration": {
"RequestIdKey": null,
"ServiceDiscoveryProvider": {
"Scheme": null,
"Host": null,
"Port": 0,
"Type": null,
"Token": null,
"ConfigurationKey": null,
"PollingInterval": 0,
"Namespace": null
},
"RateLimitOptions": {
"ClientIdHeader": "ClientId",
"QuotaExceededMessage": null,
"RateLimitCounterPrefix": "ocelot",
"DisableRateLimitHeaders": false,
"HttpStatusCode": 429
},
"QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 0,
"DurationOfBreak": 0,
"TimeoutValue": 0
},
"BaseUrl": null,
"LoadBalancerOptions": {
"Type": null,
"Key": null,
"Expiry": 0
},
"DownstreamScheme": null,
"HttpHandlerOptions": {
"AllowAutoRedirect": false,
"UseCookieContainer": false,
"UseTracing": false,
"UseProxy": true,
"MaxConnectionsPerServer": 2147483647
},
"DownstreamHttpVersion": null
}
}
As you can see, the routes I defined were not added. I tried looking on the internet for this specific issue but couldn't find anything. I don't know what I'm doing wrong, help will be appreciated.
Since your different route configuration files are located in a folder you should make sure the correct overload of the AddOcelot method is called. In this case the method should be called with the folder name containing the route files.
For example:
config.AddOcelot("Ocelot route configs", hostingContext.HostingEnvironment)
UPDATE: .NET Core 3+ with Ocelot 17.0.0
As the method AddOcelot needs an IWebHostEnvironment, and this is not available in HostBuilderContext:
You need to get it via WebHostBuilderContext:
I created two different directories Development and Production and with the below code, I'm able to read ocelot configuration according to development environment to generate the final ocelot.json that will be use by ocelot middleware.
Related
I have implemented Ocelot API Gateway in my Net Core 7 application. One of the JSON files containing routes is set up as follows:
{
"Routes": [
{
"DownstreamPathTemplate": "/storedfiletype",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "<<<HOST DELETED FOR SECURITY>>>",
"Port": 443
}
],
"UpstreamPathTemplate": "/fileserver/storedfiletype",
"UpstreamHttpMethod": [ "Post" ]
},
{
"DownstreamPathTemplate": "/storedfiletype/fileextension",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "<<<HOST DELETED FOR SECURITY>>>",
"Port": 443
}
],
"UpstreamPathTemplate": "/fileserver/storedfiletype/fileextension",
"UpstreamHttpMethod": [ "Post" ]
}
]
}
Now when I try and post to the first route (/storedfiletype in this case), I get a 404 error but the second route works. When I swap them over (making /storedfiletype/fileextension the first route), /storedfiletype works and /storedfiletype/fileextension gives me the 404 error.
Any ideas?
When trying to use IPFS from my localhost I am having trouble accessing the IPFS service. I tried setting my config to accept the localhost and all server stuff, but nothing seems to work.
The error:
Failed to load http://127.0.0.1:5001/api/v0/files/stat?arg=0x6db883c6f3b2824d26f3b2e9c30256b490d125b10a3942f49a1ac715dd2def89&stream-channels=true: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. The response had HTTP status code 403. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
IPFS Config:
{
"API": {
"HTTPHeaders": {
"Access-Control-Allow-Origin": [
"*"
]
}
},
"Addresses": {
"API": "/ip4/127.0.0.1/tcp/5001",
"Announce": [],
"Gateway": "/ip4/127.0.0.1/tcp/8080",
"NoAnnounce": [],
"Swarm": [
"/ip4/0.0.0.0/tcp/4001",
"/ip6/::/tcp/4001"
]
},
"Bootstrap": [
"/dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
"/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
"/dnsaddr/bootstrap.libp2p.io/ipfs/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
"/dnsaddr/bootstrap.libp2p.io/ipfs/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
"/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
"/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
"/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
"/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",
"/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd",
"/ip6/2604:a880:1:20::203:d001/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
"/ip6/2400:6180:0:d0::151:6001/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
"/ip6/2604:a880:800:10::4a:5001/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",
"/ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd"
],
"Datastore": {
"BloomFilterSize": 0,
"GCPeriod": "1h",
"HashOnRead": false,
"Spec": {
"mounts": [
{
"child": {
"path": "blocks",
"shardFunc": "/repo/flatfs/shard/v1/next-to-last/2",
"sync": true,
"type": "flatfs"
},
"mountpoint": "/blocks",
"prefix": "flatfs.datastore",
"type": "measure"
},
{
"child": {
"compression": "none",
"path": "datastore",
"type": "levelds"
},
"mountpoint": "/",
"prefix": "leveldb.datastore",
"type": "measure"
}
],
"type": "mount"
},
"StorageGCWatermark": 90,
"StorageMax": "10GB"
},
"Discovery": {
"MDNS": {
"Enabled": true,
"Interval": 10
}
},
"Experimental": {
"FilestoreEnabled": false,
"Libp2pStreamMounting": false,
"ShardingEnabled": false
},
"Gateway": {
"HTTPHeaders": {
"Access-Control-Allow-Headers": [
"X-Requested-With",
"Range"
],
"Access-Control-Allow-Methods": [
"GET"
],
"Access-Control-Allow-Origin": [
"localhost:63342"
]
},
"PathPrefixes": [],
"RootRedirect": "",
"Writable": false
},
"Identity": {
"PeerID": "QmRgQdig4Z4QNEqs5kp45bmq6gTtWi2qpN2WFBX7hFsenm"
},
"Ipns": {
"RecordLifetime": "",
"RepublishPeriod": "",
"ResolveCacheSize": 128
},
"Mounts": {
"FuseAllowOther": false,
"IPFS": "/ipfs",
"IPNS": "/ipns"
},
"Reprovider": {
"Interval": "12h",
"Strategy": "all"
},
"Swarm": {
"AddrFilters": null,
"ConnMgr": {
"GracePeriod": "20s",
"HighWater": 900,
"LowWater": 600,
"Type": "basic"
},
"DisableBandwidthMetrics": false,
"DisableNatPortMap": false,
"DisableRelay": false,
"EnableRelayHop": false
}
}
Ben, try replacing 127.0.0.1 with localhost. go-ipfs whitelists localhost only. Also check https://github.com/ipfs/js-ipfs-api/#cors
my answer might come very late, however I am trying to solve some CORS issues with IPFS on my end; therefore I might have a solution for you:
by running:
# please update origin according to your setup...
origin=http://localhost:63342
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["'"$origin"'", "http://127.0.0.1:8080","http://localhost:3000", "http://127.0.0.1:48084", "https://gateway.ipfs.io", "https://webui.ipfs.io"]'
ipfs config API.HTTPHeaders.Access-Control-Allow-Origin
and restarting your ipfs daemon it might fix it
if the "fetch" button in the following linked page works : you are all set ! https://gateway.ipfs.io/ipfs/QmXkhGQNruk3XcGsidCzQbcNQ5a8oHWneHZXkPvWB26RbP/
This Command Works for me
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin
'["'"$origin"'", "http://127.0.0.1:8080","http://localhost:3000"]'
you can allow the request from multiple origins
I'm building a react single page application using for backend, loopback.
How can I set, in the middleware, all the traffic (except API calls to the server and asset files like css, js,...) to go to index.html?
Here is what I have for the moment in my middleware.json configuration for the files page.:
"files": {
"loopback#static": [
{
"paths": [
"/storage"
],
"params": "$!../storage"
},
{
"paths": [
"/*"
],
"params": "$!../client/index.html"
},
{
"paths": [
"/*.*"
],
"params": "$!../client"
}
]
},
At the moment, it seems like all traffic is indeed redirected to index.html but so are the css, js, ...
Any ideas?
I am trying to find the equivalent config.json file entry in krakenjs for the below code.
app.use("/app/static", express.static(path.join(__dirname, 'public'), {maxage: '2h'}));
I tried something like the below. But, it didn't pick the mounted path
"static": {
"enabled": true,
"priority": 40,
"name": "server-static",
"module": {
"arguments": [
"path:./public",
{"maxAge" : "3h"},
"mountpath:/app/static"
]
}
}
I am unable to access it with the following URL : https://app.com/app/static/style.css. But, it is accessible via https://app.com/app/style.css
Note: /app is my requestURI.
I figured out. Here is how it is configured.
"static": {
"enabled": true,
"priority": 40,
"name": "server-static",
"module": {
"arguments": [
"path:./public",
{"maxAge" : "3h"}
]
},
"route": "/static"
},
my mup.json config for first meteor instance:
{
"servers": [
{
"host": "111.222.333.444",
"username": "root",
"password": "mypass"
}
],
"setupMongo": true,
"setupNode": true,
"nodeVersion": "0.10.40",
"setupPhantom": false,
"enableUploadProgressBar": true,
"appName": "myapp1",
"app": "../myapp1",
"env": {
"PORT": 3001,
"ROOT_URL": "https://my.domain.com"
},
"ssl": {
"pem": "./ssl.pem"
},
"deployCheckWaitTime": 15
}
So after deployment I want to get access to this instance by https://my.domain.com:3001. Then with similar configuration I want to deploy second instance to same droplet and get access to it by https://my.domain.com:3002.
The problem is that after deployment accessing by https taking ERR_CONNECTION_CLOSED, but accessing by http is OK.
How can I make it working?
Finally, I did it.
Firstly, I used mupx. But there I had troubles too. Later I found that my fault was writing same ports for different apps or protocols. So, there is working configurations of first and second apps:
{
"servers": [{
"host": "111.222.333.444",
"username": "root",
"password": "mypass",
"env": {}
}],
"setupMongo": true,
"appName": "myapp1",
"app": "../myapp1",
"env": {
"PORT": 8000,
"ROOT_URL": "http://my.domain.com"
},
"deployCheckWaitTime": 15,
"enableUploadProgressBar": true,
"ssl": {
"certificate": "../ssl/bundle.crt",
"key": "../ssl/private.key",
"port": 8001
}
}
{
"servers": [{
"host": "111.222.333.444",
"username": "root",
"password": "mypass",
"env": {}
}],
"setupMongo": true,
"appName": "myapp2",
"app": "../myapp2",
"env": {
"PORT": 8100,
"ROOT_URL": "http://my.domain.com"
},
"deployCheckWaitTime": 15,
"enableUploadProgressBar": true,
"ssl": {
"certificate": "../ssl/bundle.crt",
"key": "../ssl/private.key",
"port": 8101
}
}
bundle.crt and private.key are common for all apps.
Don't forget to use mupx.
So after
mupx setup
mupx deploy
We can get access for first app by
http://my.domain.com:8000
https://my.domain.com:8001
And for second app by
http://my.domain.com:8100
https://my.domain.com:8101
EDIT: accessing by http is not working. I don't know why, maybe it just for my configuration. But this feature I don't need, I need only https. So if you know how to fix, please, write.
EDIT2: it's alright, http access works. The reason was Chrome browser, it always redirects my domain from http to https. After cleaning browser history it do all good.