Link index.html client.js and server.js

时光毁灭记忆、已成空白 提交于 2019-12-02 08:47:07

The browser makes a request for /client.js

The server:

  1. Gets the request
  2. Runs response
  3. Reads index.html
  4. Sends it to the browser

Since index.html starts with <, the browser throws an error when it tries to run it as JavaScript.

Why are you giving the browser index.html when it asks for client.js?

You need to examine the request object, determine what URL is being asked for, write logic to return the correct resource with the correct status code and the correct content-type, and then return that to the client.

You should probably stop trying to use createServer directly — since it involves a massive amount of wheel reinvention — switch to using Express and work through the (very short) getting started guide which includes a section on using the static module to serve up static files.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!