I've made a html file and a python script to control my raspberry pi GPIO pins via websocket with the Tornado Web Server. It works great. To serve my static html page I use the following code in the python script:
application = tornado.web.Application([
(r'/escape/media/(.*)',tornado.web.StaticFileHandler,{"path":'/home/pi/myproject/media'}),
(r'/escape/(.*)',tornado.web.StaticFileHandler,{"path":'/home/pi/myproject'}),
(r'/mycode',WSHandler)
])
if __name__ == "__main__":
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(8888)
print 'Websocket Server Start ...'
tornado.ioloop.IOLoop.instance().start()
In the html file I try to load an external mp3 file to play:
function talk() {
text = encodeURI(document.getElementById("textinput").value);
mp3 = new Audio('http://translate.google.com/translate_tts?tl=en&q=' + text);
mp3.play();
}
This works if I load the webpage from my own disk on my windows machine but not when Tornado servers it as a static page from the raspberry pi. In the javascript console I get the message: "Failed to load resource: the server responded with a status of 404 (Not Found)".
I don't understand why this is a problem because it's an absolute link to an external website. Does anyone know the solution?
Thanks!