Using now-cli develop with proxy on the same localhost port to target specific instance

Michael Grondin
Kilo Expert

Hi,

I'm using the now-cli develop command to start a local web server, which works fine to display my component in the page. My issue is that I want my component to send HTTP requests to the ServiceNow API (and/or scripted REST APIs), so my component should use relative URL like /api/now/table/, because I want it to send the request to the current ServiceNow instance when it will be deployed.

The problem is that I can setup the proxy in the now-cli.json configuration to send requests to my instance, but I cannot use the same port, for instance localhost:8081, to redirect the relative URLs matching the "proxies" parameter to my ServiceNow instance.

now-cli.json example configuration:

    "development": {
        "proxy": {
            "origin": "https://<instance>.service-now.com",
            "port": 8081,
            "headers": {
                "Authorization": "Basic <creds>"
            },
            "proxies": [
                "*/api/now/*"
            ]
        },

Any ideas?
Thanks

2 REPLIES 2

royjustus
Tera Contributor

Did you figure this out? I'm not sure you are supposed to run the proxy on the same port but I can't get any of the HTTP connection sample code to work. 

DrewW
Mega Sage
Mega Sage

As far as I am aware there is no reason to set the port for the web server unless you are forced to because of something else using it.

If you have not fixed this yet here is the proxy settings that always work for me.

{
  "development": {
    "proxy": {
      "origin": "https://<YOURINSTANCE>.service-now.com",
      "headers": {
        "Authorization": "Basic <BASE64 Encoded String>"
      },
      "proxies": ["/api", "/amb", "/*.jpg"]
    },
    "test": {
        "unit": [
            "@servicenow/cli-jest-plugin"
        ]
    }
  },
  "styles": {
      "themes": [{
        "module": "@servicenow/sass-theme",
        "main": ["theme.scss"],
        "copyFiles": ["type/*", "*.scss"]
      }]
  }
}