diff --git a/config/config.go b/config/config.go index 5f9a479a138f..a4950e3e5377 100644 --- a/config/config.go +++ b/config/config.go @@ -281,7 +281,7 @@ type Config struct { ControlAPIPort int `json:"control_api_port"` EnableCustomDomains bool `json:"enable_custom_domains"` EnableJSVM bool `json:"enable_jsvm"` - JSVM string `json:"jsvm"` + EnableV2JSVM bool `json:"enable_v2_jsvm"` JSVMTimeout int `json:"jsvm_timeout"` CoProcessOptions CoProcessConfig `json:"coprocess_options"` HideGeneratorHeader bool `json:"hide_generator_header"` diff --git a/jsvm_goja.go b/jsvm_goja.go index f528d90d211a..93b4cbe51917 100644 --- a/jsvm_goja.go +++ b/jsvm_goja.go @@ -33,11 +33,9 @@ type TykJSVM interface { } func InitJSVM() TykJSVM { - - switch config.Global().JSVM { - case "goja": + if config.Global().EnableV2JSVM { return &GojaJSVM{} - default: + } else { return &OttoJSVM{} } } diff --git a/main.go b/main.go index 90078dba54e1..c3e5d8923c73 100644 --- a/main.go +++ b/main.go @@ -484,7 +484,7 @@ func loadCustomMiddleware(spec *APISpec) ([]string, apidef.MiddlewareDefinition, mwPostFuncs := []apidef.MiddlewareDefinition{} mwPostKeyAuthFuncs := []apidef.MiddlewareDefinition{} var mwDriver apidef.MiddlewareDriver - if config.Global().JSVM == "goja" { + if config.Global().EnableV2JSVM { mwDriver = apidef.GojaDriver } else { mwDriver = apidef.OttoDriver diff --git a/mw_js_plugin_test.go b/mw_js_plugin_test.go index 447b4e66235d..409a45eafa46 100644 --- a/mw_js_plugin_test.go +++ b/mw_js_plugin_test.go @@ -685,7 +685,6 @@ leakMid.NewProcessRequest(function(request, session) { func TestTykMakeHTTPRequestOtto(t *testing.T) { globalConf := config.Global() - globalConf.JSVM = "otto" config.SetGlobal(globalConf) ts := newTykTestServer() defer ts.Close() @@ -800,7 +799,7 @@ func TestTykMakeHTTPRequestOtto(t *testing.T) { func TestTykMakeHTTPRequestGoja(t *testing.T) { globalConf := config.Global() - globalConf.JSVM = "goja" + globalConf.EnableV2JSVM = true config.SetGlobal(globalConf) ts := newTykTestServer() defer ts.Close() diff --git a/mw_virtual_endpoint_test.go b/mw_virtual_endpoint_test.go index 7bb33ef102b8..041e0ba71eb3 100644 --- a/mw_virtual_endpoint_test.go +++ b/mw_virtual_endpoint_test.go @@ -79,7 +79,7 @@ func TestVirtualEndpointOtto(t *testing.T) { func TestVirtualEndpointGoja(t *testing.T) { globalConf := config.Global() - globalConf.JSVM = "goja" + globalConf.EnableV2JSVM = true config.SetGlobal(globalConf) defer resetTestConfig() ts := newTykTestServer()