Skip to content

Can't add templates directory #61

Open
@ajrice6713

Description

@ajrice6713

Attempting to create a POC with Tyk and mutate a request body to add a field before it is forwarded to the proxied URL - but I am getting an error from docker that isnt entirely clear when attempting to add templates to the root and as a volume in docker-compose.yml

My docker-compose file:

version: '3.3'
services:
  tyk-gateway:
    image: docker.tyk.io/tyk-gateway/tyk-gateway:v4.1.0
    ports:
      - 8080:8080
    networks:
      - tyk
    volumes:
      - ./tyk.standalone.conf:/opt/tyk-gateway/tyk.conf
      - ./apps:/opt/tyk-gateway/apps
      - ./middleware:/opt/tyk-gateway/middleware
      - ./templates:/opt/tyk-gateway/templates
      - ./certs:/opt/tyk-gateway/certs
    environment:
      - TYK_GW_SECRET=foo
    depends_on:
      - tyk-redis
  tyk-redis:
    image: redis:6.2.7-alpine
    networks:
      - tyk
    ports:
      - 6379:6379

networks:
  tyk:

./templates/add_app_id.tmpl:

{
    "to": "{{.to}}",
    "from": "{{.from}}",
    "text": "{{.text}}",
    "applicationId" : "abc123",  /* attempting to inject this string into every request body */
}

./apps/keyless-plugin-api.json:

{
  "name": "Tyk Test Keyless API",
  "api_id": "keyless",
  "org_id": "default",
  "definition": {
    "location": "header",
    "key": "version"
  },
  "use_keyless": true,
  "version_data": {
    "not_versioned": true,
    "versions": {
      "Default": {
        "name": "Default",
        "use_extended_paths": true,
        "extended_paths": {
          "transform": [
            {
              "path": "/keyless-test",
              "method": "POST",
              "template_data": {
                "template_mode": "file",
                "template_source": "./templates/add_app_id.tmpl",
                "input_type": "json",
                "enable_session": true
              }
            }
          ]
        }
      }
    }
  },
  "custom_middleware": {
    "pre": [
      {
        "name": "testJSVMData",
        "path": "./middleware/injectHeader.js",
        "require_session": false,
        "raw_body_only": false
      }
    ]
  },
  "driver": "otto",
  "proxy": {
    "listen_path": "/keyless-test",
    "target_url": "https://myService.m.pipedream.net/api/v1",
    "strip_listen_path": false
  }
}

Error from docker when running docker compose up -d:

time="Dec 19 21:24:03" level=info msg="Tyk API Gateway 4.1.0" prefix=main
time="Dec 19 21:24:03" level=warning msg="Insecure configuration allowed" config.allow_insecure_configs=true prefix=checkup
time="Dec 19 21:24:03" level=error msg="Could not set version in versionStore" error="storage: Redis is either down or was not configured" prefix=main
time="Dec 19 21:24:03" level=error msg="cannot set key in pollerCacheKey" error="storage: Redis is either down or was not configured"
time="Dec 19 21:24:03" level=info msg="Starting Poller" prefix=host-check-mgr
panic: html/template: pattern matches no files: `/opt/tyk-gateway/templates/error*`
goroutine 1 [running]:
html/template.Must(...)
/usr/local/go/src/html/template/template.go:372
github.com/TykTechnologies/tyk/gateway.(*Gateway).setupGlobals(0xc00012b000)
/go/src/github.com/TykTechnologies/tyk/gateway/server.go:374 +0x20c9
github.com/TykTechnologies/tyk/gateway.(*Gateway).initialiseSystem(0xc00012b000, 0x37c37275f7444d85, 0xc00013d620)
/go/src/github.com/TykTechnologies/tyk/gateway/server.go:1169 +0x44c
github.com/TykTechnologies/tyk/gateway.Start()
/go/src/github.com/TykTechnologies/tyk/gateway/server.go:1469 +0x296
main.main()
/__w/tyk/tyk/main.go:8 +0x25

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions