خرید بک لینک

Vote count: 0

I have spent too much time trying to debug this but unsure where its coming from or why I am getting this error. I am trying to make a simple website to practice react and am trying to get some data from Riot's API.

I tried to use isomorphic-fetch but ran into issues with https so I switched to express.

After switching to express I am getting "Uncaught TypeError: Caot read property 'prototype' of undefined.

I am also using browserify-middleware if that matters at all.

Here is the file that is causing issues.

// import fetch from 'isomorphic-fetch';

// var myHeaders = new Headers();

var express = require('express')
var app = express();

var apiURL = 'https://na.api.pvp.net/api/lol/na/v1.4/';
var apiToken = '?api_key=dbada37c-b6c0-43fe-bf1f-f1819507b3d7';


// export function fetchSummonerInfo() {
//  retu fetch(apiURL + 'summoner/by-name/Faxious' + apiToken, {
//      method: 'GET',
//      mode: 'no-cors'
//  })
//      .then((data) => console.log(JSON.stringify(data)))
//      // .catch((e) => console.log(e))
//      // .then((res) => console.log(res))
// }
// 

// app.use(function(req, res, next) {
//  res.header("Access-Control-Allow-Origin", "*");
//  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
//  next();
// })

export function fetchSummonerInfo() {
    app.get(apiURL + 'summoner/by-name/Faxious' + apiToken, middle,  function(req, res) {
        let body = ""
        res.on('data', function(data) {
            body += data;
        })
        res.on('end', function() {
            console.log(body);
        })
    })
}

function middle(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    next();
}

asked 13 secs ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 15 تير 1395 ساعت: 3:31

صفحه بندی