我使用 amazon Route 53 购买了一个域名,创建了一个弹性 IP 地址并将其附加到运行 MEAN bitnami 堆栈的 Amazon EC2 实例,然后我创建了一个用于静态 Web 托管的 S3 存储桶,“将所有请求重定向”到 www.domainname.com 。
但是,当我转到根域时,加载的页面是 Bitnami 祝贺页面:您现在正在云中运行 Bitnami MEAN 3.2.11-0。我创建了一个文件夹,上传了 MEAN Angular 2/express 应用程序并执行了 Node server.js,我只能在 mydomain.com:8080 上访问我的 Web 应用程序,但其他任何内容都会重定向到 Bitnami 祝贺页面。这是哪个设置在执行此操作?是亚马逊设置的吗?Bitnami 设置?或者我的服务器端代码中的某些内容。我在服务器代码中唯一提到 8080 的地方是这里,当我运行服务器时,它会打印在 8080 上运行的 API:
const port = process.env.PORT || '8080';
app.set('port', port);
const server = http.createServer(app);
server.listen(port, () => console.log(`API running on: ${port}` + ' or ' + process.env.PORT));
Run Code Online (Sandbox Code Playgroud) 在 Ubuntu 18.04 上设置 nodejs 项目时出现以下错误。安装的 npm 版本是 6.x,安装的 node 版本是 10.x。
bcrypt@3.0.3 install /home/ubuntu/reko_dev/web/backend/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build
node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp WARN Tried to download(404): https://github.com/kelektiv/node.bcrypt.js/releases/download/v3.0.3/bcrypt_lib-v3.0.3-node-v64-linux-x64-glibc.tar.gz
node-pre-gyp WARN Pre-built binaries not found for bcrypt@3.0.3 and node@10.15.0 (node-v64 ABI, glibc) (falling back to source compile with node-gyp)
gyp ERR! build error
gyp ERR! stack Error: not found: make
gyp ERR! stack at getNotFoundError (/usr/lib/node_modules/npm/node_modules/which/which.js:13:12)
gyp ERR! stack at F …Run Code Online (Sandbox Code Playgroud) 我一直在通过反复试验的方式自学 Node.js。我使用 Node.js HTTP 类构建了一个简单的服务器。我发现我可以异步读取文件并使用异步
fs.readFile(..., cbk)回调方法提供数据。我目前不明白的是如何响应请求所需的所有其他资源。
// "./index.js"
var http = require('http');
var fs = require('fs');
http.createServer(function (req, res){
fs.readFile('index.html', function(err, data){
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
res.end();
});
}).listen(8080);
Run Code Online (Sandbox Code Playgroud)
为了保持一个焦点,我将仅用
Style-sheets作示例。下面是一个超级常见的链接标签,它演示了我通常如何告诉服务器页面需要特定的 CSS 文件。它在事物的前端工作得很好。但是,如何处理来自服务器端(或后端)的链接标记的请求?
<link rel="stylesheet" type="text/css" href="/foo/bar/raboof.css">
Run Code Online (Sandbox Code Playgroud)
我一直在查看这里对这个问题的答复,但没有任何帮助我。有些解决方案也给我带来了更多错误。
我想做的是使用 Node.JS 路由到不同的页面。在学习了一些 MEAN 堆栈后,我决定使用 Node、Express 和 Angular(尚未实现)。如果我尝试访问“/”路线以外的任何地方,我会收到一条错误消息“找不到模块‘html’”。下面是有问题的代码:
//dependencies
var express = require('express');
var path = require('path');
var engines = require('consolidate')
//variables
var RUN_PORT = 8080;
var VIDEO_IN_PORT = 45679;
var CONTROL_OUT = 45678;
var app = express();
app.use(express.static(path.join(__dirname, 'public')));
//index.html routing
app.get('/', function(req, res){
res.render("index.html");
});
//robot_control.html routing
app.get('/robot_control', function(req, res){
res.render("robot_control.html");
});
//error.html routing
app.get('/error', function(req, res){
res.render("error.html");
});
//showing that the program is running on the RUN_PORT
app.listen(RUN_PORT, function(){
console.log("Running on port " + RUN_PORT);
}); …Run Code Online (Sandbox Code Playgroud) mean-stack ×4
node.js ×3
express ×2
amazon-ec2 ×1
bcrypt ×1
bitnami ×1
javascript ×1
mean ×1
meanjs ×1
npm-install ×1
ubuntu-18.04 ×1