lundi 20 juin 2016

Feeding information from one JS server into another with Ember

We are currently using the Steam API for an Ember project, but have found out that the API doesn't allow cross-origin requests. As a result, we created a server based of documentation found here.

While we have created a server that is able to successfully call the API and get the info we requested, we have found that the server runs on port: 4000, and we need it to connect to port: 4200.

Is there a way for us to push the info from this server to the ember server? Any help would be much appreciated.

Below is the code we used for the server:

var express = require('express');

var app = express();

app.get('/', function(httpRequest, httpResponse) {
    httpResponse.send('Hello, World!');
});

app.get('/hello-frank', function(httpRequest, httpResponse) {
httpResponse.send('Hello, Frank.');
});

app.post('/hello-frank', function(httpRequest, httpResponse) {
httpResponse.send("No, Frank. You're not allowed to post.");
});

app.get('/hello/:name', function(httpRequest, httpResponse) {
var name = httpRequest.params.name;
httpResponse.send('Hello, ' + name + '!');
});

var request = require('request');

var url = 'http://ift.tt/28LK7Z6' +
'v2/?key=YOURSTEAMAPIKEYHERE&appid=8930';


request.get(url, function(error, steamHttpResponse, steamHttpBody) {
// Print to console to prove we downloaded the achievements.
console.log(steamHttpBody);
});

app.get('/steam/civ5achievements', function(httpRequest, httpResponse) {
// Calculate the Steam API URL we want to use
var url = 'http://ift.tt/28LK7Z6' +
    'v2/?key=YOURSTEAMAPIKEYHERE&appid=8930';
request.get(url, function(error, steamHttpResponse, steamHttpBody) {
    // Once we get the body of the steamHttpResponse, send it to our client
    // as our own httpResponse
    httpResponse.setHeader('Content-Type', 'application/json');
    httpResponse.send(steamHttpBody);
});
});


app.get('/steam/game/:appid/achievements', function(httpRequest, httpResponse) {
// Calculate the Steam API URL we want to use
var url = 'http://ift.tt/28LK7Z6' +
    'v2/?key=YOURSTEAMAPIKEYHERE&appid=' +
    httpRequest.params.appid;
request.get(url, function(error, steamHttpResponse, steamHttpBody) {
    httpResponse.setHeader('Content-Type', 'application/json');
    httpResponse.send(steamHttpBody);
});
});


app.use('/', express.static('public'));


var bodyParser = require('body-parser');

app.use(bodyParser.text());


app.post('/frank-blog', function(httpRequest, httpResponse) {
console.log(httpRequest.body);

httpResponse.status(200).send('Posted today:\n\n' + httpRequest.body);

var port = 4000;
var server = app.listen(port);
console.log('Listening on port ' + port);




Aucun commentaire:

Enregistrer un commentaire