I'm in need of some fresh perspective.
My goal is to have a basic Express app return JSON data (in this case, a Firebase token) every time a request is made to it.
Here's the code for my Express server:
app.get('/validate', function (req, res) {
var customToken = firebase.auth().createCustomToken(req.query.token);
res.json({
token: customToken
});
});
app.listen(8000, function () {
console.log('Listening on port 8000');
});
This is how the client sends a request (running on port 3000):
export function login() {
return fetch('http://localhost:8000/validate?token=666', {
method: 'GET',
mode: 'no-cors',
headers: new Headers({
'Authorization': apiClient.headers.Authorization,
'Content-Type': 'application/json'
})
})
.then(response => console.log('RESPONSE: ', response.json()))
.catch(response => console.error('ERROR: ', response));
}
The Express app seems to be functioning correctly as I can view the necessary JSON when I visit
http://localhost:8000/validate?token=666
in a browser.
However, upon making the client request, I encounter the following error:
Uncaught (in promise) SyntaxError: Unexpected end of input
and the Response log displays like this:
RESPONSE: Promise {[[PromiseStatus]]: "rejected", [[PromiseValue]]: SyntaxError: Unexpected end of input↵ at SyntaxError (native)↵ at eval (eval at <anonymous> (h…}__proto__: Promise[[PromiseStatus]]: "rejected"[[PromiseValue]]: SyntaxError: Unexpected end of input↵ at SyntaxError (native)↵ at eval (eval at <anonymous> (http://localhost:3000/main.js:1381:2), <anonymous>:78:42)message: "Unexpected end of input"stack: "SyntaxError: Unexpected end of input↵ at SyntaxError (native)↵ at eval (eval at <anonymous> (http://localhost:3000/main.js:1381:2), <anonymous>:78:42)"get stack: stack()set stack: stack()__proto__: Error
login.js?b88c:54
If you have any insights on what mistake I might be making, I would greatly appreciate it.