# Detect dev mode within javascript files

**URL:** https://discourse.roots.io/t/detect-dev-mode-within-javascript-files/24860
**Category:** sage
**Tags:** bud, webpack, sage10
**Created:** 2023-02-24T17:44:38Z
**Posts:** 2

## Post 1 by @sage_fish — 2023-02-24T17:44:38Z

Is there a way to detect when I am in dev mode within my javascript files. The reason being is that I am using wp-api-request to get a REST posts collection and I get a console error.

My dev server is :

```
http://localhost:3000/wp-json/wp/v2/posts
```

and production server is:

```
http://localhost:8000/wp-json/wp/v2/posts
```

When I make the request in dev mode I get a console error,

```
http://localhost:8000/wp-json/wp/v2/posts 403 (Forbidden)
```

This is confirmed when I print out wpApiSettings.root. It shows as,

```
wpApiSettings.root = 'http://localhost:8000/wp-json/
```

Is there a config variable I can access to detect when I am using the dev server so that I can change wpApiSettings.root to the dev sever?

---

## Post 2 by @ben — 2023-02-24T21:24:54Z

Some options:

- Use something like [GitHub - ahmadawais/WP-REST-Allow-All-CORS: Allow all cross origin requests to your WordPress site's REST API.](https://github.com/ahmadawais/WP-REST-Allow-All-CORS)
- Set your `WP_HOME` to dev server URL
