未找到脚本:404

时间:2017-11-19 15:07:06

标签: javascript html handlebars.js

我的项目名称是"篮球。"我有一个"观点"夹。 " views"中的一个文件是"个人资料,"这是用户更改个人资料的页面。

我在Basketball中添加了一个文件夹,我将其命名为"脚本。"在脚本内部,我添加了一个文件" profile.js。"

在我看来,我最后有了:

<script type="text/javascript" src="/scripts/profile.js"></script>

当我运行应用程序时,出现错误:

 GET http://localhost:3000/scripts/profile.js 404 (Not Found)

除了无法加载脚本外,视图还可以正常工作。

我的道路有什么问题?还是有其他错误?

1 个答案:

答案 0 :(得分:1)

即使您包含一些script/css/image或任何其他文件,您需要在服务器端设置其路由器以将该文件提供给浏览器(除非您使用其他模块为您执行此操作,如express) 。如果您不想使用express,我建议您这样做,您可以在服务器端编写router。像

这样的东西
if(req.url === '/scripts/profile.js' ){
res.writeHead(200, {'Content-type' : 'text/javascript'});
fs.createReadStream(path.join(path.join(__dirname,'scripts/profile.js'),'split.css'), 'utf8' ).pipe(res)

}

相关问题