简体   繁体   中英

How to use Moment.js with Apigee API proxy?

How do I properly include and use Moment.js in my Apigee API proxy?

In included version 2.8.2 in the policy: <IncludeURL>jsc://include/moment.min.js</IncludeURL>

Whether or not I try to use it in my main JavaScript file, the API request always returns an error:

{
    "fault": {
        "faultstring": "Execution of reformatBookingDetails failed with error: Javascript runtime error: \"Cannot modify a property of a sealed object: moment. (reformatBookingDetails_js#6)\"",
        "detail": {
            "errorcode": "steps.javascript.ScriptExecutionFailed"
        }
    }
}

I also tried the following. Instead of using IncludeURL I manually copied the Moment.js code at the top of my main JavaScript file. But I got the same error.

Update: I tried previous versions of Moment.js, and I found that version 2.5.1 does not have this issue. This issue appears to have been introduced in 2.6.0

This doesn't seem like an apigee specific problem. If you try to run this javascript outside of the apigee runtime, you might still see the same problem. Its hard to say, without looking at your javascript code what the problem could be.

You might also want to take a look at this thread for reference: https://bugzilla.mozilla.org/show_bug.cgi?id=203013

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM