简体   繁体   中英

Failed to load resource: the server responded with a status of 404 (Not Found) - javaScript CSS files

I've been unable to get css and js to load on my server. MY file structure is as follows: GAME_Folder 在此处输入图像描述

HTML

doctype html
head
  link(href='https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap' rel='stylesheet')
  script(src='https://code.jquery.com/jquery-latest.min.js' type='text/javascript')
  script(src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js')
  <script type="text/javascript" src="index.js"></script>
  link(rel='stylesheet' type='text/css' href='../css/style.css')
  script(src='/socket.io/socket.io.js')

Server (serv.js)

在此处输入图像描述

I've tried almost everything from the previous stack overflow posts: Failed to load resource: the server responded with a status of 404 (Not Found) Failed to load resource: the server responded with a status of 404 (Not Found) css

Any other suggestions?

Your routing is wrong...

It should be like this:

app.use(express.static(__dirname + '/public/style.css');
app.use(express.static(__dirname + '/public/index.js');

And in your HTML file:

doctype html
head
  link(href='https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap' rel='stylesheet')
  script(src='https://code.jquery.com/jquery-latest.min.js' type='text/javascript')
  script(src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js')
  <script type="text/javascript" src="index.js"></script>
  link(rel='stylesheet' type='text/css' href='/css/style.css')
  script(src='/socket.io/socket.io.js')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM