【发布时间】:2017-02-23 23:06:55
【问题描述】:
你好 stackoverflow 成员,
这是我的第一个问题,所以请温柔。
目前我有一个运行 node.js 的 Amazon-web-service(AWS) 服务器。 我已经从 AWS 的 node.js 示例项目中复制了 node.js 文件。
////node.js
var port = process.env.PORT || 3666,
http = require('http'),
fs = require('fs'),
html = fs.readFileSync('index.html');
var log = function(entry) {
fs.appendFileSync('/tmp/sample-app.log', new Date().toISOString() + ' - ' + entry + '\n');
};
var server = http.createServer(function (req, res) {
if (req.method === 'POST') {
var body = '';
req.on('data', function(chunk) {
body += chunk;
});
req.on('end', function() {
if (req.url === '/') {
log('Received message: ' + body);
} else if (req.url = '/scheduled') {
log('Received task ' + req.headers['x-aws-sqsd-taskname'] + ' scheduled at ' + req.headers['x-aws-sqsd-scheduled-at']);
}
res.writeHead(200, 'OK', {'Content-Type': 'text/plain'});
res.end();
});
} else {
res.writeHead(200);
res.write(html);
res.end();
}
});
// Listen on port 3000, IP defaults to 127.0.0.1
server.listen(port);
// Put a friendly message on the terminal
console.log('Server running at http://127.0.0.1:' + port + '/');
我如何在标题中写我只得到 index.html。 这就是它在控制台中的样子
bundle.js:1 Uncaught SyntaxError: Unexpected token
如果我在网络选项卡中打开 bundle.js(来自 chrome),则只有 index.html 中的代码
////index.html
<!doctype html>
<html class="no-js" lang="ger" dir="ltr">
<head>
<meta charset="UTF-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script type="text/javascript" src="bundle.js" charset="utf-8"></script>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.6.7.js" type="application/javascript"></script>
</head>
<body>
<h1>test</h1>
<div ng-view></div>
<script>
$(document).foundation();
</script>
</body>
</html>
Node JS and Webpack Unexpected token < 这里有其他人同样的问题(可能),但我了解他们只推荐了其他服务器应用程序(Express)到什么程度? 但是因为我使用 AWS 我只能使用 node.js
和bundle.js无关这个问题有任何JavaScript文件。
我没有使用 node.js 的经验,我只想加载 Javascript 文件。
解决方法:我可以正确使用和加载 http 调用。但这非常耗时。我需要在我的 AWS s3 存储桶上加载所有 Js 文件(甚至是我的模块控制器)。
这是一个单页应用程序,包含许多自定义 Javascript 文件和模块。 Here a screenshot from my directory
期待你的回答!
【问题讨论】:
-
发布您的 HTML 文件。
-
but how far I've understand they've only recommended an other server application(Express)? But cause I use AWS I can only use node.js仅供参考,Express 是一个节点模块,您可以在任何节点应用程序中使用 express,无论它在何处运行,无论是 AWS、Heroku 还是您的本地机器。 -
这是一个 webpack 错误!!,您的 Node 部分和 HTML 无关紧要。问题在于构建捆绑包。
-
@todarist 你可以访问任何其他 js 文件吗?还是css文件?如果是,则检查 bundle.js 文件路径是否正确。当路径不可访问时也会出现此错误。
-
我认为这个问题在这里是相关的stackoverflow.com/questions/33260093/…
标签: javascript angularjs node.js amazon-web-services webpack