2017-01-19 5 views
0

を提供していない:Expressは自動的にこれが私のディレクトリ構造であるindex.htmlを静的ファイル

build/ (contains gulp tasks for generating dist from src) 
dist/ (this is the static app I'm serving) 
    (all other assets, css, images, etc) 
    index-5c1755df65.html 
src/ (source files, can't be served through express) 
express/ (express app + API) 
    app.js 

は、ここに私の特急app.jsです:

//Enable Helmet security fixes - dnsPrefetchControl, clickjacking prevention, poweredBy hide, HSTS, ieNoOpen, MIME type sniffing and XSS prevention 
app.use(helmet()); 

//Parse the body of the request as a JSON object, part of the middleware stack (https://www.npmjs.com/package/body-parser#bodyparserjsonoptions) 
app.use(bodyParser.json()); 

//Serve static Angular JS assets from distribution, part of the middleware stack, but only through HTTPS 
//--------The following line used to work!--------- 
app.use('/', ensureSecure, express.static('dist'); 

//Import routes (Removed getToken router. BH Token is processed through a helper) 
app.use('/api', [router_invokeBhApi]); 
//404 Redirect on unhandled url 
app.use('*', function (req, res, next) { 
    res.status(404).sendFile(__dirname + '/views/404.html'); 
}); 

//Setup port for access 
app.listen(process.env.PORT || 3000, function() { 
    console.log(`The server is running on port ${process.env.PORT || 3000}!`); 
}); 

私は角1.4.3ある(dist全体にサービスを提供するために使用app)を上のコードでその行に置き換えて、インデックスファイルを提供していましたが、その名前にランダムな暗号が含まれていました。

一部のアップデートの後、動作を停止しました。今私はnpmからserve-staticと呼ばれる外部ライブラリを使用して、これを実行する必要があります:

app.use('/', ensureSecure, serveStatic('dist', {'index': ['index-5c1755df65.html', 'index.html']})); 

これを修正する方法がわから、またはものではありませんが、この急激な変化をもたらしました。それはブラウザですか?または角度? (私の最新の変更と1.4.3から1.5.8にアップグレード)

EDIT:私のhtmlファイル

<!doctype html> 
<html lang="en"> 
    <head> 
     <meta charset="utf-8"> 
     <!--REMOVED ALL THE META TAGS FOR STACK OF PURPOSES--> 
     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/> 
     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 
     <title>IMG Career Portal</title> 
     <!-- default font --> 
     <!--<link href='//fonts.googleapis.com/css?family=Roboto:400,700,500' rel='stylesheet' type='text/css'>--> 
     <link href='https://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'> 
     <!-- Font Awesome --> 
     <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel='stylesheet' type='text/css'> 
     <link rel="stylesheet" href="styles/vendor-f398fee98b.css"> 

     <link rel="stylesheet" href="styles/app-292a67e7f9.css"> 
    </head> 
    <body> 

     <!-- Main Application Tag (Angular2 Ready :)) --> 
     <main></main> 



     <script src="scripts/vendor-ec12e9202e.js"></script> 

     <script src="scripts/app-8e0fb1a5c9.js"></script> 
    </body> 
</html> 

私は、アプリをビルドして実行、きれいにgulp expressを実行します。

gulp.task('express', ['clean','build'], function(){ 
    nodemon({ 
     script: 'express/app.js' 
    }); 
}); 
+0

あなた '.html'ファイル –

+0

申し訳ありませんああ、私は@SayuriMizuguchi – ykadaru

答えて

0

アプリためです。 jsはheadタグ内の作業が必要です。

あなたが集中APIを使用してindex.htmlファイルのinicializateをしたい場合:

app.get('/', function(req, res){ 
    res.render("../yourpaste/index"); //the new index.ejs file 
     }); 

headタグ内でごapp.jsを入れて試してみてください、あなたのapp.jsに

module.exports = app; 

を追加します。

<!doctype html> 
<html lang="en"> 
    <head> 
     <script src="scripts/app-8e0fb1a5c9.js"></script> //your app.js 
     <meta charset="utf-8"> 
     <meta name="description" content="Official career portal of the Ian Martin Group, an Engineering & IT recruiting B Corporation."> 
     <meta property="og:title" content="Ian Martin Group: Careers"> 
     <meta property="og:description" content="Find the next great step in your Engineering or IT career here."> 
     <meta property="og:image" content="https://media.glassdoor.com/o/de/b1/5f/51/the-ian-martin-group-all-company-retreat-2015.jpg"> 
     <meta property="og:url" content="https://careers.ianmartin.com"> 
     <meta name="twitter:title" content="Ian Martin Group: Careers"> 
     <meta name="twitter:description" content="Find the next great step in your Engineering or IT career here."> 
     <meta name="twitter:image" content="https://media.glassdoor.com/o/de/b1/5f/51/the-ian-martin-group-all-company-retreat-2015.jpg"> 
     <meta name="twitter:card" content="summary_large_image"> 
     <meta property="og:site_name" content="IMG Careers"> 
     <meta name="twitter:image:alt" content="Great company culture."> 
     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/> 
     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 
     <title>IMG Career Portal</title> 
     <!-- default font --> 
     <!--<link href='//fonts.googleapis.com/css?family=Roboto:400,700,500' rel='stylesheet' type='text/css'>--> 
     <link href='https://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'> 
     <!-- Font Awesome --> 
     <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel='stylesheet' type='text/css'> 
     <link rel="stylesheet" href="styles/vendor-f398fee98b.css"> 

     <link rel="stylesheet" href="styles/app-292a67e7f9.css"> 
    </head> 
    <body> 

     <!-- Main Application Tag (Angular2 Ready :)) --> 
     <main></main> 



     <script src="scripts/vendor-ec12e9202e.js"></script> 


    </body> 
</html> 
+0

今これを追加しましたが、それはindex-を検出できない場合はどのようにapp.js(表現)は、HTML内から実行されます(追加してくださいランダムな文字列).htmlファイルを最初に? – ykadaru

+0

形式を通知しないと、自動的に.htmlファイルの名前が取得されます。しかし、もし "ejs"が設定されていれば、あなたは設定されていません。例: 'app.set( 'view engine'、 'ejs');'設定しないと、htmlファイル –

関連する問題