简体   繁体   English

Express JS:我还能吗 <scripts> 在我的index.html中

[英]Express JS: Can I still have <scripts> in my index.html

When converting an index.html page to be served up by Express, instead of Webstorm, I noticed that all my scripts suddenly reported 404 - Not Found , where previously they were found just fine. 当转换要由Express而不是Webstorm提供服务的index.html页面时,我注意到我的所有脚本突然报告404 - Not Found ,以前发现它们很好。

Should I not be serving up a page from Express that has a bunch of tags? 我是否应该从Express中投放带有大量标签的页面? If it is OK to do so, how come they are all 404-Not found now, where previously they were found just fine? 如果可以的话,为什么现在都404-Not found以前找不到它们)?

EDIT: Directory structure: project --- src --- js main.js --- css index.html app.js <-- all the express code 编辑:目录结构: project --- src --- js main.js --- css index.html app.js <-- all the express code

Express code includes these lines: Express代码包括以下几行:

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

Make sure Express is set up to serve your static assets. 确保已设置Express以服务您的静态资产。 By default it will serve these from /public 默认情况下,它将从/public

app.use(express.static(path.join(__dirname, 'public')));

You can add your scripts there (recommended!) or add additional express.static statements pointing to your specific scripts folder. 您可以在此处添加脚本(推荐!),也可以添加指向特定脚本文件夹的其他express.static语句。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果没有 index.html,如何在 index.html 中运行脚本 - How to run scripts in index.html in react if you don't have index.html 我怎样才能通过js保护我的index.html网站所以我只能在我的电脑上打开它? - how can i protect my index.html website by js so i can only open it on my pc? 在index.html中使用node.js脚本 - Using node.js scripts in index.html 如果我在 index.html 的脚本标记中使用异步,我是否需要费心在 scripts.js 中编写异步代码? 我要javascript - If I use async in my script tag in index.html do I need to bother with writing async code in scripts.js? I am asking for javascript webpacks (react-scripts) index.html 中的 JS 在做什么? - What is the JS in webpacks (react-scripts) index.html doing? 如何使用Javascript将流数据(已转换为颜色的数据)不断地推送到index.html中的连续div中? - How can I push constantly streaming data (which I have converted to color) into successive divs in my index.html using Javascript? 如何在 Docusaurus V2 的 index.html 的头部添加自定义脚本? - How can I add custom scripts in index.html's head part in Docusaurus V2? Express.js 服务生成的 index.html 问题 - Express.js serving generated index.html issue Express.js重定向到HTTPS并发送index.html - Express.js redirect to HTTPS and send index.html 我不能 append 在 js 文件中创建的 div<section> ,在我的 index.html 中的网格内</section> - I'm can't append a div created in js file inside a <section>, whitch is inside a grid, in my index.html
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM