# WebDev CORS error in V8.1.5

**URL:** <https://forum.inductiveautomation.com/t/webdev-cors-error-in-v8-1-5/49575>\
**Category:** Ignition Early Access\
**Tags:** ignition80\
**Created:** [August 5, 2021, 3:22am UTC](https://forum.inductiveautomation.com/t/webdev-cors-error-in-v8-1-5/49575 "2021-08-05T03:22:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jianping.li](https://avatars.discourse-cdn.com/v4/letter/j/c89c15/32.png) [@jianping.li](https://forum.inductiveautomation.com/u/jianping.li)\
**Post date:** [August 5, 2021, 3:22am UTC](https://forum.inductiveautomation.com/t/webdev-cors-error-in-v8-1-5/49575/1 "2021-08-05T03:22:38Z")

</div>

I tried to develop a webdev api. And When I create a post method, when I request from client, I entered a cors error. Then I tried to add a cors header like this:

servletResp = request[‘servletResponse’]  
servletResp.addHeader(‘Access-Control-Allow-Origin’, ‘\*’ )  
servletResp.setHeader(“Access-Control-Allow-Methods”, “POST, GET, PUT, OPTIONS, DELETE”)

It works in v7.9 and v8.0， but now I use v8.1.5 and it seems dosen’t work.  
Need help!

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 5, 2021, 4:10pm UTC](https://forum.inductiveautomation.com/t/webdev-cors-error-in-v8-1-5/49575/2 "2021-08-05T16:10:22Z")

</div>

Are you only implementing `doPost`? To properly support CORS, you should be implementing `doOptions` to return your rewritten CORS headers.

---

<div class="post-metadata">

**Author:** ![Muti\_Gozel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/muti_gozel/32/72908_2.png) [@Muti\_Gozel](https://forum.inductiveautomation.com/u/Muti_Gozel)\
**Post date:** [January 18, 2023, 7:34pm UTC](https://forum.inductiveautomation.com/t/webdev-cors-error-in-v8-1-5/49575/3 "2023-01-18T19:34:51Z")

</div>

Can you share an example for this? I cannot find any examples.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 18, 2023, 7:39pm UTC](https://forum.inductiveautomation.com/t/webdev-cors-error-in-v8-1-5/49575/4 "2023-01-18T19:39:07Z")

</div>

The original post has a script that looks like it should work, as long as it's implemented in the right HTTP method. What header values you want to return are up to you.

---

<div class="post-metadata">

**Author:** ![Muti\_Gozel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/muti_gozel/32/72908_2.png) [@Muti\_Gozel](https://forum.inductiveautomation.com/u/Muti_Gozel)\
**Post date:** [January 18, 2023, 8:02pm UTC](https://forum.inductiveautomation.com/t/webdev-cors-error-in-v8-1-5/49575/5 "2023-01-18T20:02:49Z")

</div>

I created a python resource on Web Dev Module and implemented the doGet method as the following. As you can see it returns a json list object with the list of tags that has history.

I'm trying to develop a html/js/jquery app on my local dev machine (mind that dev machine is different than the server). The JS Fetch API is throwing the CORS error.

How can I overcome this to allow CORS error to allow any origin temporarily (until I finish development)?

```auto

def doGet(request, session):
	tags = list(parse_tags())
	return { "json": tags }
	
def parse_tags():
	tags = system.tag.browseTags(parentPath="", recursive=True)
	
	for tag in tags:
		path = str(tag.fullPath)
		
		has_history = parse_has_history(path)
		
		if not has_history:
			continue
		
		name = str(tag.name)
		type = str(tag.tagType)
		data_type = str(tag.dataType)
		
		yield { 
			"path": path, 
			"name": name, 
			"type": type, 
			"data_type": data_type, 
			"has_history": str(has_history),
			"check": False,
			}

def parse_has_history(path):
	try:
		return len([x for x in system.tag.getConfiguration(path) if x["historyEnabled"] == True]) > 0
	except:
		return False

```

---

<div class="post-metadata">

**Author:** ![Muti\_Gozel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/muti_gozel/32/72908_2.png) [@Muti\_Gozel](https://forum.inductiveautomation.com/u/Muti_Gozel)\
**Post date:** [January 18, 2023, 8:07pm UTC](https://forum.inductiveautomation.com/t/webdev-cors-error-in-v8-1-5/49575/6 "2023-01-18T20:07:53Z")

</div>

Here is my code doGet method below. I'm trying to return list of interest tags as json list.

In another environment I'm trying to develop html/jquery app that utilizes this function, but JS Fetch API is getting CORS error.

How can I overcome this? Any help would be much appreciated.

```auto
def doGet(request, session):
	tags = list(parse_tags())
	return { "json": tags }
	
def parse_tags():
	tags = system.tag.browseTags(parentPath="", recursive=True)
	
	for tag in tags:
		path = str(tag.fullPath)
		
		has_history = parse_has_history(path)
		
		if not has_history:
			continue
		
		name = str(tag.name)
		type = str(tag.tagType)
		data_type = str(tag.dataType)
		
		yield { 
			"path": path, 
			"name": name, 
			"type": type, 
			"data_type": data_type, 
			"has_history": str(has_history),
			"check": False,
			}

def parse_has_history(path):
	try:
		return len([x for x in system.tag.getConfiguration(path) if x["historyEnabled"] == True]) > 0
	except:
		return False

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 18, 2023, 9:27pm UTC](https://forum.inductiveautomation.com/t/webdev-cors-error-in-v8-1-5/49575/7 "2023-01-18T21:27:02Z")

</div>

You will have to do research on [simple](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests) vs [preflighted](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#preflighted_requests) requests. You might have to implement the `doOptions` header, depending on the exact nature of the request you're trying to serve with Webdev.

---

<div class="post-metadata">

**Author:** ![jcjc74836](https://avatars.discourse-cdn.com/v4/letter/j/439d5e/32.png) [@jcjc74836](https://forum.inductiveautomation.com/u/jcjc74836)\
**Post date:** [August 10, 2023, 10:32pm UTC](https://forum.inductiveautomation.com/t/webdev-cors-error-in-v8-1-5/49575/8 "2023-08-10T22:32:14Z")

</div>

First, have you use Postman? for testing your request.

---

<div class="post-metadata">

**Author:** ![chaoliang](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@chaoliang](https://forum.inductiveautomation.com/u/chaoliang)\
**Post date:** [October 25, 2023, 4:38am UTC](https://forum.inductiveautomation.com/t/webdev-cors-error-in-v8-1-5/49575/9 "2023-10-25T04:38:14Z")

</div>

I have the similar issue.

Postman works fine but React.js not good, having the CORS issue.
