Skip to content

Instantly share code, notes, and snippets.

@cbejensen
Last active December 6, 2018 19:11
Show Gist options
  • Save cbejensen/cb23a2bb102cd8d7dc5ac0c6d7005f90 to your computer and use it in GitHub Desktop.
Save cbejensen/cb23a2bb102cd8d7dc5ac0c6d7005f90 to your computer and use it in GitHub Desktop.
Getting no response when sending GET request from localhost:3000 to localhost:8000
// currently running on localhost:3000
const xhr = new XMLHttpRequest()
const url = 'localhost:8000/'
xhr.open('GET', url)
xhr.onreadystatechange = function() {
console.log(xhr.responseText) // logs nothing
}
xhr.send()
const express = require('express')
const cors = require('cors')
const app = express()
const port = 8000
app.use(cors())
app.get('/', (req, res) => {
console.log('got a get request') // never logs
res.send('ok')
})
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment