我正在处理这个小的平均堆栈应用程序,当我的镜像被点击时,它会显示一个带有图像信息的部分,一切正常,但是在刷新角试图从错误的url获取app.js文件之后:http://localhost:3000/image/56afc07d5e1fea4839791b55发送get请求给http://localhost:3000/image,这是错误的,因此它找不到角app.js文件。
如何在Node中为静态文件提供服务:
app.use(express.static(path.join(__dirname, '/public')));
app.use('/bower_components', express.static(__dirname + '/bower_components'));
app.use('/node_modules', express.static(__dirname + '/node_modules'));
app.use('/uploads', express.static(__dirname + "/uploads"));
app.get('/*', function(req, res) {
res.sendFile(__dirname +'/public/index.html');
});这是角app.js中的路由:
app.config(function(
$routeProvider,
$locationProvider) {
$routeProvider
.when('/', {
templateUrl: '/partials/main.html',
access: {restricted: false}
})
.when('/signup', {
templateUrl: '/partials/signup.html',
controller: 'authCtrl',
access: {restricted: false}
})
.when('/login', {
templateUrl: '/partials/login.html',
controller: 'authCtrl',
access: {restricted: false}
})
.when('/gallery', {
templateUrl: '/partials/gallery.html',
controller: 'authCtrl',
access: {restricted: true}
})
.when('/image/:id', {
templateUrl: '/partials/imageView.html',
controller: 'imageViewCtrl',
access: {restricted: true}
})
.otherwise({
redirectTo: '/'
});更新
只有在使用param在页面上刷新时才会出现问题,例如: localhost:3000/image/id。在localhost上刷新:3000/映像时,当在localhost上:3000/image/id和我重新加载页面时,它尝试从localhost:3000而不是localhost:3000获取数据。
发布于 2016-02-08 19:20:00
我的错误太愚蠢了。快递是正确的路由应用程序,但在index.html文件中,我添加了
角的app.js文件:
<script type="text/javascript" src="app.js"></script>因此,没有"/"之前的app.js,如果url更长,那么localhost:3000/app.js:
本地主机:3000/图片库/图像角试图下载相应的app.js :3000/图片库。
将app.js脚本添加到index.html中的正确方法
<script type="text/javascript" src="/app.js"></script>https://stackoverflow.com/questions/35258266
复制相似问题