Endpoint not exported error (it is exported)

Hi,

I have had an endpoint on RunKit for over a year now, maybe even two years, built using the Express endpoint helper.

Problem

The other day I updated the code and republished the notebook, and now the endpoint is completely inaccessible, and I am getting an error that endpoints aren’t being exported. They are—I did not change the express server/endpoint part of the notebook, only some aspects of private functions on the back end. On top of this, the endpoint logs show that the endpoint is indeed being contacted and returning the correct data. It’s only on the client side that the endpoint is being blocked with the message ‘Endpoint is not being exported’. I am at a loss here for what to do.

Description

The endpoint is for a Google PlusCode/Open Location Code conversion service, and two endpoints are exported, /encode and /decode. The encode endpoint takes a URL parameter of comma-separated latitude and longitude (e.g. /encode/29.144,40.543). The decode endpoint either takes only a URL parameter with a fully-formed Google PlusCode/Open Location Code (e.g. /decode/6P8RCCFW) or a ‘Short Code’ form of a Google Plus/Open Location Code with an additional required q query parameter for the region in which to query for the Short Code. (e.g. /decode/CCFW+6P4?q=Lahore, Pakistan). Obviously all parameters should be URI-encoded before hitting the endpoint.

Notebook

Background

Read more about Google PlusCodes/Open Location Codes here and here.

There’s a subtle error in your code. On line 40 you’re redeclaring module.exports = {} which means that the exports that is in scope when your notebook is reevaluated now points to a different object.

So when you do const app = express(exports); the express helper is adding the endpoint handler to the wrong object. When the endpoint is being spun up RunKit is looking for a endpoint field on module.exports, which doesn’t exist. Hence the error.

If you change the above line to const app = express(module.exports); that will fix your problem. It’s not clear to me how the endpoint could have ever worked before though.

- Randy

1 Like

Understood—I’m not sure how it was working before either, but it was made a few years ago so maybe something changed.

Thanks for your help! I got it working again.