Express app定义的`static`文件夹无法正常工作(Express app defined `static` folder not working properly)
在我的
express
应用程序中,我已经声明了静态文件夹。 而且我还将我的index.html
保存在静态文件夹中。 但我为新目的创建了一个新的router
。 当我创建一个新的router
我的静态文件夹总是试图使用声明的新router
获取资产。 任何人帮我解决这个问题?这是我的代码和问题:
var express = require("express"), app = express(), Router = express.Router; app.use( express.static(__dirname + '/puplic')); //my public folder var oneTime = new Router(); //my new router oneTime.get("*", function( req, res ) { res.sendFile( __dirname + "/public/oneTime/index.html"); }); app.use("/oneTime", oneTime); app.listen( 9000, function portCallback() { console.log(" I am started!!" , __dirname); })
但我的应用程序试图获得像这样的
angular
js:问题是什么?
这是html我怎么称呼我的angualr:
<script src="oneTime/angular.min.js"></script>
实际上我期待这样:
In my
express
app, I have declared the static folder. And I am keeping myindex.html
as well in the static folder. But I have created a newrouter
for a new purpose. when i create a newrouter
my static folder always trying to get the assets using the newrouter
declared. any one help me to sort this issue?here is my code and issue :
var express = require("express"), app = express(), Router = express.Router; app.use( express.static(__dirname + '/puplic')); //my public folder var oneTime = new Router(); //my new router oneTime.get("*", function( req, res ) { res.sendFile( __dirname + "/public/oneTime/index.html"); }); app.use("/oneTime", oneTime); app.listen( 9000, function portCallback() { console.log(" I am started!!" , __dirname); })
But my app trying to get the
angular
js like this:what is the issue?
here is the html how i call my angualr:
<script src="oneTime/angular.min.js"></script>
actually I am expecting like this:
满意答案
选项1
你可以改变这一行:
app.use( express.static(__dirname + '/puplic')); //my public folder.
至
app.use('/oneTime', express.static(__dirname + '/puplic')); //my public folder
选项2
我假设你在公共文件夹中有一个
js
文件夹,然后你需要更改你的HTML代码:<script src="js/angular.min.js"></script>
并且服务器代码将是
app.use( express.static(__dirname + '/puplic')); //my public folder.
Option 1
You can change this line:
app.use( express.static(__dirname + '/puplic')); //my public folder.
to
app.use('/oneTime', express.static(__dirname + '/puplic')); //my public folder
Option 2
I am assuming you have a
js
folder in the public folder, then you need to change your html code:<script src="js/angular.min.js"></script>
and the server code will be
app.use( express.static(__dirname + '/puplic')); //my public folder.
相关问答
更多表示从隐藏(点)文件夹中提供静态文件(Does express serve static files from hidden (dot) folder)
带有nodejs和express的静态文件夹(Static folder with nodejs and express)
nodejs表示不拦截具有静态内容的文件夹的消息(nodejs express not to intercept messages for a folder with static content)
Dynamic express.static()文件夹路径(Dynamic express.static() folder path)
无论如何,Node.js中的Express可以有多个静态文件夹?(Is there anyway Express in Node.js can have more than one static folder?)
Express server静态文件夹不提供文件(Express server static folder does not serve files)
Express js不提供静态文件(Express js does not serve static files)
Express app定义的`static`文件夹无法正常工作(Express app defined `static` folder not working properly)
快速父文件夹访问(Express parent folder access)
Node.js Express无法获取静态文件,路由比一个文件夹级别更深(Node.js Express not able to get static files and route is deeper then one folder level)
相关文章
更多Working on Free Software
关于继承和static的小问题
Twitter Storm Real-Life App 排错记
全球最流行的66款App的共同规律
Windows Phone 获取app在商店中的版本(检查app的版本号)
JavaFx Main中怎么绑定Java类中的一个static变量呢?
一个效果很华丽的仿桌面APP,却胜似Launcher
微信公众平台,移动APP的推广利器
在java中如何获取文件夹占用空间的大小?(注意这里不是问文件夹大小)
手机app
最新问答
更多绝地求生、荒野行动、香肠派对 哪个更好玩???(都是吃鸡类游戏)
如何在jQuery集合中选择第n个jQuery对象?(How to select the nth jQuery object in a jQuery collection?)
ASP NET使用jQuery和AJAX上传图像(ASP NET upload image with jQuery and AJAX)
SQL Server XML查询中包含名称空间的位置(SQL Server XML query with namespaces in the where exist)
宁夏银川永宁县望远镇哪里有修mp5的?
我想用更新的日期标记所有更新的行(I would like to mark all updated rows with the date that they have been updated)
郑州会计培训班
如何定位数组中的负数,并得到所有正数的总和?(How to target e negative number from an array, and get the sum of all positive numbers?)
在响应图像上叠加网格(Overlay grid on responsive image)
无法让POST在Azure网站上运行(Could not get POST to work on Azure Website)
Copyright ©2023 656463.com All Rights Reserved.滇ICP备2022006988号-50
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们,本站将尽快处理。谢谢合作!