How do I display res.send values from custom API (on heroku) in a text field?

0 favourites
  • 2 posts
From the Asset Store
A very simple to set up ZElevation based depth of field system for your game. Fully commented.
  • Hi there!

    I believe this is my first post and while I always try to resolve my problems through searching, this has me totally stumped and quite frustrated!

    So here's what the issue is...

    I have a nodejs/express app that creates endpoints which send out specific data from MongoDB. I have hosted this on heroku and have npm install cors as well as doen the usual app.use to allow access-control headers.

    If I test the end point in a browser, I get the complete json string but if I test in c3, I get a CORS issue. Even when I export the C3 game to html 5 and host it on another server of mine, I get the same issue. The only way I sort of get past it is by using a CORS plugin in my browser (firefox) which then gives me a value of null!

    Here's my url to see the API end point GET -> (/getImages)- > guess-the-word-v1.herokuapp.com/getImages

    and this is my c3 code

    Now when I try this out in a standard chrome browser, I get a CORS error (despite having set -

    const cors = require("cors" )

    app.use(cors())

    Forgetting the above, if I test with the CORS plugin inbrowser, I get the following response ->

    That seems to indicate, its not waiting for an asynchronous fetch. How do I set an async event in C3? I thought the AJAX - on "tag" completed would wait for the callback?

    Hoping someone can help point me in the right direction!

    PS : Next I am going to try the complete js - await fetch in a script... will that work?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • btw I am also thinking Firebase if this does not work, but I would reallllllllly love this to work as it gives me so much control over data manipulation if I have my own API!

    Final Query - I intend to complete the game and publish it for Facebook Instant. Is that likely to create some new complications with API end point permissions? (I am hoping not!)

    thanks in advance and cheers! :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)