routes[0].headers is not a object in vercel.json - vercel

I have been trying to deploy an a Flask API to vercel and I am getting error that routes[0].header should be an object.
I am a beginner and trying to figure this out, any help is appreciated
my vercel.json is
`
{
"version": 2,
"builds": [
{
"src": "./index.py",
"use": "#vercel/python"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "/",
"headers": [
{
"key": "access-control-allow-origin",
"value": "*"
}
]
}
]
}
`
i deployed earlier without headers and it deployed successfully but it was giving me CORS error then i addded the headers and now it is giving me a new error that headers is not a object.
i tried a few different methods but i still can not figure this out

I encountered similar issue and after going through vercel documents https://vercel.com/guides/how-to-enable-cors and few different tries, this worked for me:
The header has to be its own key for specifying access-control-allow-origin and "routes" will need to be replaced with "rewrite" as header and route keys don't go together. And If there are few different domains for your app, you need to duplicate header object within the outer header array for each path for access control origin issue.
Eg:
{
"version": 2,
"builds": [
{
"src": "./index.py",
"use": "#vercel/python"
}
],
"rewrites": [
{ "source": "/(.*)", "destination": "src/app.js" }
],
"headers": [
{
"source": "/(.*)",
"headers": [
{ "key": "Access-Control-Allow-Origin", "value": "*" }
]
},
{
"source": "/vercel_app_domain_name/(.*)",
"headers": [
{ "key": "Access-Control-Allow-Origin", "value": "*" }
]
}
]
}

Related

NPM serve rewrites issue

I have this configuration for serve (serve.json):
{
"headers": [
{
"source": "**/**",
"headers": [
{
"key": "Content-Security-Policy",
"value": "frame-ancestors 'none'"
},
{
"key": "X-Frame-Options",
"value": "deny"
}
]
}
],
"rewrites": [
{ "source": "/**", "destination": "/index.html" },
{ "source": "/logout", "destination": "/logout.html" }
]
}
When running 'serve build' (build being the folder where the html files are served from) and trying to access localhost/logout, I'm redirected to index.html.
The desired behaviour is to use logout.html when accessing logout route.
It looks like "/**" takes priority as every time I'm redirected to index.html.
Thank you
Though I hadn't yet confirmed it, have you considered reversing the order, so that the explicit rules (such as /logout) are earlier in the array than the implicit/wildcard rewrite rules (such as /**)?

jfrog artifactory "invalid character '"' after object key:value pair"

So I have this spec file in artifactory to remove folders (with artifacts inside) older than 3 months in more than one repository (3 in this example).
{
"files": [{
"aql": {
"items.find": {
"$or": [{
"$and": [{
"repo": "repo1",
"path": "com/domain/repo1",
"created": {
"$before": "3mo"
}
"type": "folder",
"name": {"$match":"20*"}
}],
"$and": [{
"repo": "repo2",
"path": "com/domain/repo2",
"created": {
"$before": "3mo"
}
"type": "folder",
"name": {"$match":"20*"}
}],
"$and": [{
"repo": "repo3",
"path": "com/domain/repo3",
"created": {
"$before": "3mo"
}
"type": "folder",
"name": {"$match":"20*"}
}]
}]
}
}
}]
}
But I´m getting: [Error] invalid character '"' after object key:value pair
How can I tell what is the (") that is causing the error? is not quite descriptive the output like in some other languajes that tells you the line number at least.
On the other hand, if I use following spec for a single repository, it works like a charm.
thank you!
{
"files": [{
"aql": {
"items.find": {
"repo": "repo5",
"path": "com/domain/repo5",
"created": {
"$before": "3mo"
},
"type":"folder",
"name": {"$match":"20*"}
}
}
}]}
You are missing a comma after all of the "created" key/value pairs:
"created": {
"$before": "3mo"
} <-- missing a comma here
"type": "folder",
Please notice that your working example has the comma in the right place.

GraphJSON serialization in Gremlin.Net

I'm trying to query the TinkerPop server (hosted inside docker container) via CosmosDB client library, which uses under the hood Gremlin.Net. So I managed to connect it and insert the data, here's intercepted WebSocket request:
!application/vnd.gremlin-v1.0+json{
"requestId": "b64bd2eb-46c3-4095-9eef-768bca2a14ed",
"op": "eval",
"processor": "",
"args": {
"gremlin": "g.addV(\"User\").property(\"UserId\",2).property(\"CustomerId\",1)"
}
}
The response:
{
"requestId": "b64bd2eb-46c3-4095-9eef-768bca2a14ed",
"status": {
"message": "",
"code": 200,
"attributes": {
"host": "/172.19.0.1:38848"
}
},
"result": {
"data": [
{
"id": 0,
"label": "User",
"type": "vertex",
"properties": {}
}
],
"meta": {}
}
}
Problem is that I see those properties when I'm connected via gremlin console
gremlin> g.V().hasLabel("User").has("CustomerId",1).has("UserId",2).limit(1).valueMap()
==>{UserId=[2], CustomerId=[1]}
Also, I'm able to query the TinkerPop server with Gremlin.Net:
!application/vnd.gremlin-v1.0+json{
"requestId": "de35909f-4bc1-4aae-aa5f-28361b3c0933",
"op": "eval",
"processor": "",
"args": {
"gremlin": "g.V().hasLabel(\"User\").has(\"CustomerId\",1).has(\"UserId\",2).limit(1)"
}
}
But it returns a payload with zero-valued ID and without any properties included:
{
"requestId": "de35909f-4bc1-4aae-aa5f-28361b3c0933",
"status": {
"message": "",
"code": 200,
"attributes": {
"host": "/172.19.0.1:38858"
}
},
"result": {
"data": [
{
"id": 0,
"label": "User",
"type": "vertex",
"properties": {}
}
],
"meta": {}
}
}
Tried to swap between GraphSON v1, v2, v3 with no luck. Documentation says that script serializers should include all the properties. Do I have to tweak the config somehow to make this work and return properties?
So it seems that with a version of 3.4 of the Gremlin server ReferenceElementStrategy
was added by default to traversals, to preserve compatibility between binary and script serializers. In our case we wanted to mimic the behavior of the CosmosDB, so to adjust and receive desired behavior just remove the strategy from init script (in our case it was empty-sample.groovy
globals << [g : graph.traversal().withStrategies(ReferenceElementStrategy.instance())]
to
globals << [g : graph.traversal()]

Forwading URL Through Cloudflare API

I'm trying to create a page rule using Cloudflare's API to forward http to https. Unfortunately, I don't think the documentation is 100% clear on how to do this. Here is the JSON object I'm currently passing to the POST body:
{
"targets": [
{
"target": "url",
"constraint": {
"operator": "matches",
"value": "http://exampletest.com/*"
}
}
],
"actions": [{
"id": "forwarding_url",
"value": "https://exampletest.com/$1"
}]
}
and here is the message I'm getting back:
{
"success": false,
"errors": [
{
"code": 1004,
"message": "Page Rule validation failed: See messages for details."
}
],
"messages": [
{
"code": 1,
"message": ".settings[0].url: This value should not be blank.",
"type": null
},
{
"code": 2,
"message": ".settings[0].statusCode: This value should not be blank.",
"type": null
}
],
"result": null
}
So it seems like I need to have a settings object somewhere, but any way I try to add the settings, I'm getting the same message. Does anyone know what I'm doing wrong here? Here is Cloudflare's Documentation on the subject. Not sure if I might be missing something:
https://api.cloudflare.com/#page-rules-for-a-zone-create-page-rule
Actually, just figured this one out. It looks like this is the correct format:
{
"targets": [
{
"target": "url",
"constraint": {
"operator": "matches",
"value": "http://exampletest.com/*"
}
}
],
"actions": [
{
"id": "forwarding_url",
"value": {
"url": "https://www.exampletest.com/$1",
"status_code": 301
}
}
]
}
You have to set a parameter - "status":"active" to actually activate the page rule or else you're just creating an inactive rule.
Cloudflare sets this as an optional parameter, but it is needed to activate the rule.
The updated version of this answer goes like this:
{
"targets": [
{
"target": "url",
"constraint": {
"operator": "matches",
"value": "http://exampletest.com/*"
}
}
],
"actions": [
{
"id": "forwarding_url",
"value": {
"url": "https://www.exampletest.com/$1",
"status_code": 301
}
}
],
"status": "active"
}

How to update existing Knowledgebase using QnA Maker API v4.0?

I've successfully created my Knowledgebase using API.
But I forgot to add some alternative questions and metadata for one of the pairs.
I've noticed PATH method in the API to update the Knowledebase, so updating kb is supported.
I've created a payload which looked like this:
{
"add": {
},
"delete": {
},
"update": {
"qnaList": [
{
"id": 1,
"answer": "Answer",
"source": "link_to_source",
"questions": [
"Question 1?",
"Question 2?"
],
"metadata": [
{
"name": "oldMetadata",
"value": "oldMetadata"
},
{
"name": "newlyAddedMetaData",
"value": "newlyAddedMetaData"
}
]
}]}
}
I get back the following response HTTP 202 Accepted:
{
"operationState": "NotStarted",
"createdTimestamp": "2018-05-21T07:46:52Z",
"lastActionTimestamp": "2018-05-21T07:46:52Z",
"userId": "user_uuid",
"operationId": "operation_uuid"
}
So, looks like it worked. But in reality, this request doesn't take any affect.
When I check operation details, it returns me the following:
{
"operationState": "Succeeded",
"createdTimestamp": "2018-05-21T07:46:52Z",
"lastActionTimestamp": "2018-05-21T07:46:54Z",
"resourceLocation": "/knowledgebases/kb_uuid",
"userId": "user_uuid",
"operationId": "operation_uuid"
}
What am I doing wrong? And how should I update my kb via API properly?
Please help
I had the same problem, I discovered that it was necessary to have all the data of the json even if they were not used.
In your case you need "name" and "urls" in the "update" section and "Delete" in "update/qnaList/questions" section:
{
"add": {},
"delete": {},
"update": {
"name": "nameofKbBase", //this
"qnaList": [
{
"id": 2370,
"answer": "DemoAnswerEdit",
"source": "CustomSource",
"questions": {
"add": [
"DemoQuestionEdit"
],
"delete": [] //this
},
"metadata": { }
}
],
"urls": [] //this
}
}