JS file gets a net::ERR_ABORTED 404 (Not Found)

前端 未结 1 1730
Happy的楠姐
Happy的楠姐 2021-01-04 11:51

I am trying to create a simple Io-web-chat. I recently wanted to seperate my

1条回答
  •  臣服心动
    2021-01-04 12:43

    As mentionned in comments: you need a way to send your static files to the client. This can be achieved with a reverse proxy like Nginx, or simply using express.static().

    Put all your "static" (css, js, images) files in a folder dedicated to it, different from where you put your "views" (html files in your case). I'll call it static for the example. Once it's done, add this line in your server code:

    app.use("/static", express.static('./static/'));
    

    This will effectively serve every file in your "static" folder via the /static route.

    Querying your index.js file in the client thus becomes:

    
    

    0 讨论(0)
提交回复
热议问题