Nodejs-client not building with vue.js

Hey, we are using the nodejs-client in our vue app to read the palyable status from an uploaded video. We are getting the following error when building our app:

 ERROR  Failed to compile with 1 error                                                                                        1:47:46 PM

 error  in ./node_modules/@api.video/nodejs-client/lib/HttpClient.js

Module parse failed: Unexpected token (95:57)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|                             // @ts-ignore
|                             const { response } = error;
>                             const contentType = response?.headers['content-type'];
|                             if (contentType === 'application/problem+json') {
|                                 // @ts-ignore

 @ ./node_modules/@api.video/nodejs-client/lib/index.js 15:37-60
 @ ./src/plugins/ApiVideo.ts
 @ ./src/main.ts
 @ multi (webpack)-dev-server/client?http://192.168.1.110:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.ts

Weirdly the error above concerns the ? operator… I think this could be related to our typescript settings or project setup or maybe I’m just overlooking something - We are using typescript with target: es2015 and module: esnext. I forked your package and tried to compile it with similar targets but that didn’t work. I already tried to use different module and target configs without luck.

We also use the video-uloader package, there everything works fine. Any ideas what I could try?

I got it working by manually modifying the built output and replacing the chaining ? with a proper if/else expression. But this solution is more like “just for testing”. So I updated the tsconfig of the node-client to target es2017.

However, as the package is using the got package there is a dependency to dns and http2, which are both deprecated. There is more about this issue on the got repo here. The bottom line is that got (and apparently the node client) is intended to be used only on server side.

So I apparently shouldn’t use the nodejs-client with vue. I guess I will have to use webhooks for video encoding instead, and track the playable status within our own database.

Hi Giorgio,

Sorry, for some reason your post above was automatically marked as spam by the system. I just removed the flag, and your post is now public.
Thanks for sharing this with us. I have raised it to the eng team to see if we could provide an alternative, longer-term solution to this issue you are raising. We will keep you informed!

Cheers,
Alex
Product | api.video

1 Like

Hi Giorgio,

As you said yourself, this client isn’t intented to be used on the front-end side. That would require you to put your private api key on the front end, and that would lead to a severe security issue.

The proper way to achieve what you’re trying to do is to call our API from your backend (using on the our API clients, depending on your backend technology) and to forward the status to your frontend.

You can also use our webhooks. An endpoint of your backend will be called by the webhook and you’ll be able to relay the event to your frontend (using socket.io by instance).

Hope this will help.

Regards,

Olivier

Hey thanks for the updates, yeah don’t worry I just didn’t see that the node.js client isn’t intended to be used with frontends (one of the reasons being the security issues that you mentioned),

In the end we implemented the webhooks solution :slight_smile:

1 Like