Cannot get on http://localhost:3000/

时间:2017-04-04 09:43:58

标签: gulp browser-sync

I am using gulp.The tasks are getting run creating required folders. But I get Cannot GET/ error when run in browser.I have attached the image of my project structure and also the output in command line command line output中使用ui-router的路由问题。Project Structure。我的index.html包含以下内容

<!DOCTYPE html>
<html lang="en" ng-app="helloWorldApp">
    <head>
        <title>Angular hello world app</title>
        <link href="css/main.css" rel="stylesheet">
    </head>
    <body>
        <ng-view class="view"></ng-view>
    </body>
    <script src="js/scripts.js"></script>
</html>

我想知道为什么它无法正常路由以及应该做什么。所以问题是当服务器在localhost上运行时我点击localhost:3000 /在浏览器中它说无法获得白色背景。以下是我的gulpfile.js

const gulp = require('gulp');
const concat = require('gulp-concat');
const browserSync = require('browser-sync').create();

const scripts = require('./scripts');
const styles = require('./styles');

var devMode = false;



gulp.task('css',function(){
    gulp.src(styles)
        .pipe(concat('main.css'))
        .pipe(gulp.dest('./dist/css'))
        .pipe(browserSync.reload({
            stream : true
    }))
});

gulp.task('js',function(){
    gulp.src(scripts)
        .pipe(concat('scripts.js'))
        .pipe(gulp.dest('./dist/js'))
        .pipe(browserSync.reload({
            stream : true
    }))
});

gulp.task('html',function(){
    gulp.src('./templates/**/*.html')
        .pipe(gulp.dest('./dist/html'))
        .pipe(browserSync.reload({
            stream : true
    }))
});

gulp.task('build',function(){

    gulp.start(['css','js','html']);
     console.log("finshed build");
});

gulp.task('browser-sync',function(){
    browserSync.init(null,{
        open : false,
        server : {
            baseDir : 'dist'
        }
    });
     console.log("finshed browser ");
});

gulp.task('start',function(){
    devMode = true;
    gulp.start(['build','browser-sync']);
    gulp.watch(['./css/**/*.css'],['css']);
    gulp.watch(['./js/**/*.js'],['js']);
    gulp.watch(['./templates/**/*.html'],['html']); 
});

2 个答案:

答案 0 :(得分:2)

您需要将browserSync指向dist/html/index.html文件作为index的起始页。

gulp.task('browser-sync',function(){
    browserSync.init(null,{
        open : false,
        server : {
            baseDir : 'dist',
            index : "html/index.html"
        }
     });
     console.log("finshed browser ");
});

答案 1 :(得分:1)

由于你的baseDir是&#39; dist&#39;你需要在浏览器中运行http://localhost:3000/html我觉得应该可以运行。