server:
var http = require('http')
var fs = require('fs')
//404
function _404(response) {
response.writeHead(404, {'Context-Type': 'text/plain'})
response.write('error 404, not found')
response.end()
}
http.createServer(onRequest).listen(8080)
console.log('server is running')
function onRequest(request, response) {
if (request.method == 'GET' && request.url == '/') {
response.writeHead(200, {'Context-Type': 'text/html'})
fs.createReadStream('./testhtml.html').pipe(response)
} else {
_404(response)
}
}
works fine when i enter into my browser and call with localhost:8080, but am trying to connect to it with my phone (not on this network connection, but 4G) by entering my ip and port (XXX.XXX.XXX.XXX:8080)
Why is this not working, am i doing something wrong?
Answer from another question [duplicate]:
Don't forgot to forward your port through router settings cause the router is receiving the requests not your PC
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments