api-now icon indicating copy to clipboard operation
api-now copied to clipboard

All non-GET requests return 403 Forbidden when using https

Open Rick-Kirkham opened this issue 2 years ago • 3 comments

All non-GET requests return 403 Forbidden when using https

  • bug: I'm working with HTTPS. I can read the db.json just fine with GET requests. But all POST, PUT, PATCH, etc. requests to write to the file return 403 Forbidden.

Environment Details

  • api-now version: 0.5.4
  • OS: Windows 10
  • Node.js version: 16.13.2

Long Description I'm working with HTTPS. I can read the db.json just fine with GET requests. But all POST, PUT, PATCH, etc. requests to write to the file return 403 Forbidden. The following screenshot is from the Fiddler tool. The same thing is seen in the console of the F12 tools.

image

This screenshot is of the server window:

image

const getData = () => { 
  fetch('https://localhost:3001/posts/1')           //api for the get request
  .then(response => response.json())
  .then(data => console.log(data));
};

const newPost =  {
  "id": 2,
  "title": "json-server",
  "author": "Rick"
}
// Options to be given as parameter
// in fetch for making requests
// other then GET
let options = {
	method: 'PUT',
	headers: {
		'Content-Type':	'application/json;charset=utf-8'
	},
	body: JSON.stringify(newPost)
}

const setData = () => { 
  fetch('https://localhost:3001/posts/1', options)           //api for the set request
  .then(response => response.json())
  .then(data => console.log(data));
};

Workaround

none ...

(Please help with a PR if you have a solution. Thanks!)

Rick-Kirkham avatar May 10 '23 22:05 Rick-Kirkham

metoo

left0ver avatar May 27 '23 07:05 left0ver

UPDATE: It really has nothing to do with HTTPS. It happens with HTTP too. The problem is that the server needs to set CORS headers and the documentation doesn't say how to do that.

Rick-Kirkham avatar May 30 '23 16:05 Rick-Kirkham