无法访问 http://localhost:3000/

Cannot get on http://localhost:3000/

我正在使用 gulp.The 任务正在 运行 创建所需的文件夹。但是当 browser.I 中的 运行 附加了我的项目结构的图像以及命令行 . 中的输出时,我得到无法获取/错误。我的 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>

我想知道为什么不能正确路由或无法正确路由以及应该如何处理。所以问题是当服务器在本地主机上 运行ning 并且我在浏览器中点击 localhost:3000/ 它说无法获得白色 background.Following 是我的 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']); 
});

您需要将 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 ");
});

因为你的 baseDir 是 'dist' 你需要在浏览器中 运行 http://localhost:3000/html 我认为应该可以。