Express为Elastic Beanstalk中的所有GET提供索引

时间:2018-06-16 05:42:13

标签: node.js express elastic-beanstalk

我已经设置了一个快速服务器来提供HTML文件和一个发布的js文件。当它在localhost上使用node.js服务器运行时,一切正常。但是在Elastic Beanstalk Node.js环境中,index.html正确提供,对于bundle.js文件,index.html再次被提供,导致'意外令牌<'错误。 (不是babel的问题。它已经被反编译了。)

var express = require('express');
var app = express();
var fs = require("fs");
const bodyParser = require('body-parser');

app.use(express.static("code"));
app.use(bodyParser.urlencoded({extended: true}));

app.get('/', function (req, res) {
   fs.readFile( __dirname + "/" + "index.html", 'utf8', function (err, data) {
       res.end( data );
   });
})

//added this part since it wasn't served with 
//app.use(express.static("code"));
app.get('/bundle.min.js', function (req, res) {
   fs.readFile( __dirname + "/code/" + "bundle.min.js", 'utf8', function (err, data) {
       res.end( data );
   });
})


var server = app.listen(8080, function () {
})

server.js

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.13/semantic.min.css">
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</head>

<body>
    <div id="root"></div>
    <script src="bundle.min.js"></script>
</body>

</html>

的index.html

0 个答案:

没有答案