我有一个Angular/NodeJS应用程序,添加了Socket.io支持以获得一些实时功能.
我想添加MongoDB和PassportJS支持,所以我已经迁移到generator-angular-fullstack结构.
突然,Socket.io功能不再起作用了.
我发现的一个错误是Socket.io服务的客户端JS库http://localhost/socket.io/socket.io.js现在从我的应用程序返回index.html页面.
这听起来像路由问题,所以这是我的路由配置:
lib/routes.js(NodeJS):
module.exports = function(app) {
    // Server API Routes
    app.get('/api/awesomeThings', api.awesomeThings);
    app.post('/api/users', users.create);
    app.put('/api/users', users.changePassword);
    app.get('/api/users/me', users.me);
    app.get('/api/users/:id', users.show);
    app.post('/api/session', session.login);
    app.del('/api/session', session.logout);
    // All other routes to use Angular routing in app/scripts/app.js
    app.get('/partials/*', index.partials);
    app.get('/*', middleware.setUserCookie, index.index);
    app.get('/:session', function(req, res) {
        res.render('views/index.html', {
            title: 'Weld Spark'
        });
    });
};
app/scripts/app.js(AngularJS):
angular.module('weld.common').config(function($routeProvider, $locationProvider, $httpProvider) {
    $routeProvider
        .when('/main', {
            templateUrl: 'partials/main',
            controller: 'MainCtrl'
        })
        .when('/login', {
            templateUrl: 'partials/login',
            controller: 'LoginCtrl'
        })
        .when('/signup', …我使用meanIO推荐的模块'swig'作为模板引擎.但我无法在获得角度基本数据绑定方面表现出色.
在NodeJS平台上的快速服务器中进行以下设置:
 app.engine('html', consolidate[config.templateEngine]);
 app.set('view engine', 'html');
  app.get('/', function(req,res){
    var values = {
        appName : config.appname
    }
    res.render('page1');
    //res.redirect('/login');
});
上面的设置不会在填充文本框时呈现实际的角度模型.
 <div>
  <label>Name:</label>
  <input type="text" ng-model="yourName" placeholder="Enter a name here">
  <hr>
  <h1>Hello {{yourName}}!</h1>
以下设置对我来说非常好.
app.engine('html', require('ejs').renderFile); // to render html files in response
app.set('view engine', 'html');
swig模块没有在{{}}内呈现ng-model数据有什么问题?
更新:感谢JohnnyHK的回答,我的问题已经解决了!
初步问题:为什么我收到以下错误消息的任何想法?请注意,即使程序正常运行,"我们已连接"行之前的所有内容都会打印出来.
DEBUG=cfcwebportal:* ./bin/www
[Error: /home/ben/Code For Chicago/cfcwebportal/node_modules
/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/build/Release/bson.node: invalid ELF header]
js-bson: Failed to load c++ bson extension, using pure JS version
[Error: /home/ben/Code For Chicago/cfcwebportal/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/build/Release/bson.node: invalid ELF header]
js-bson: Failed to load c++ bson extension, using pure JS version
[Error: /home/ben/Code For Chicago/cfcwebportal/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/build/Release/bson.node: invalid ELF header]
js-bson: Failed to load c++ bson extension, using pure JS version
[Error: /home/ben/Code For Chicago/cfcwebportal/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/build/Release/bson.node: invalid ELF header]
js-bson: Failed to load c++ bson extension, using pure JS version
We …有很多讨论并赞成基于标记的MEAN应用程序身份验证体系结构是安全的。但是我有一个问题,那就是它是否确实将用户名和密码作为授权和身份验证作为JSON Web令牌中的有效载荷传递,并且如果我们没有在有效载荷中传递安全信息,那么JSON Web Token如何在服务器中没有用户名/口令的情况下对用户进行身份验证侧。
我读了很多架构方面的文章,但是他们不能解释在不使用用户名/密码的情况下,他们使用了什么逻辑来验证令牌。
将身份验证令牌存储在cookie中而不是在Web存储中是否有效?
是的,我知道他们使用私钥和公钥进行验证,但这不足以进行身份验证。要验证特定用户,它需要一些密钥值,例如用户名/密码或标识特定用户所需的任何密钥访问权限。
目前的情绪
我正试图在我的控制器中定义的以下函数中从Angular发出$ http post请求:
$scope.sendUserData = function(){
    var userData = JSON.stringify({
        'firstName': $scope.firstName,
        'lastName': $scope.lastName,
        'email': $scope.email
    });
    console.log(userData); //this prints out the JSON I want
    var config = {
        headers: {
            'Content-Type': 'json'
        }
    };
    $http.post('/api/users', userData, config)
        .success(function(data){
            console.log(data);
        })
        .error(function(data){
            console.log('Error: ' + data)
        });
我有一个Express API,我想通过下面定义的路由处理程序接收这个$ http post请求:
router.route('/users')
.post(function(req, res){
    var user = new User();
    user.firstName = req.body.firstName;
    user.lastName = req.body.lastName;
    user.email = req.body.email;
    user.save(function(error){ //add into mongodb
        if(error){
            res.send(error);
        }
        else{
            res.json({message: 'User created'}); …嗨,我正在尝试通过猫鼬创建一个新的子文档,但是当我在邮递员中执行POST方法时,我收到以下消息:
{
  "message": "Location validation failed",
  "name": "ValidationError",
  "errors": {
    "reviews.1.reviewText": {
      "message": "Path `reviewText` is required.",
      "name": "ValidatorError",
      "properties": {
        "type": "required",
        "message": "Path `{PATH}` is required.",
        "path": "reviewText"
      },
      "kind": "required",
      "path": "reviewText"
    },
    "reviews.1.rating": {
      "message": "Path `rating` is required.",
      "name": "ValidatorError",
      "properties": {
        "type": "required",
        "message": "Path `{PATH}` is required.",
        "path": "rating"
      },
      "kind": "required",
      "path": "rating"
    },
    "reviews.1.author": {
      "message": "Path `author` is required.",
      "name": "ValidatorError",
      "properties": {
        "type": "required",
        "message": "Path `{PATH}` is required.", …我需要学习如何使用带有角度2.0和打字稿的MEAN堆栈...我知道我可以使用JS,但我需要使用typescript.
我一直在浏览https://angular.io/guide/quickstart指南,我正在接触NG2,但我现在面临的问题是如何将所有技术链接在一起,我无法找到任何展示如何互动的地方使用MongoDB通过NG2 + TS.
我想知道是否有任何关于MEAN2堆栈的教程,或者解释如何在NG2中使用mongoose.
谢谢
尝试在我的AWS EC2 ubuntu服务器上安装这里angular-fullstack中的angular-fullstack框架
运行后出现此错误'gulp serve':
module.js:471 throw err;
Error: Cannot find module './build/bindings/encode.node' at ...
在我的Mac OS上一切正常.我只在我的ubuntu服务器上收到此错误.
救命?请!!!
一些信息:
操作系统:Ubuntu 16.04
在Angular 4文档中,路由的代码片段如下所示:
导入模块:
import { RouterModule, Routes } from '@angular/router';
路由示例:
const appRoutes: Routes = [
  { path: 'crisis-center', component: CrisisListComponent },
  { path: 'hero/:id',      component: HeroDetailComponent },
  {
    path: 'heroes',
    component: HeroListComponent,
    data: { title: 'Heroes List' }
  },
  { path: '',
    redirectTo: '/heroes',
    pathMatch: 'full'
  },
  { path: '**', component: PageNotFoundComponent }
];
@NgModule({
  imports: [
    RouterModule.forRoot(
      appRoutes,
      { enableTracing: true } // <-- debugging purposes only
    )
    // other imports here
  ],
  ...
})
export class AppModule …使用MEAN堆栈连接到我的服务器时遇到问题。直到今天,我都没有连接问题,并且从那以后也没有进行任何代码更改,因此我对为什么突然无法连接感到困惑。
连接:
mongoose.connect("mongodb+srv://theller5567:" + process.env.MONGO_ATLAS_PW + "@cluster0-efzkv.mongodb.net/node-angular", { useNewUrlParser: true })
.then(() => {
    console.log("Connected to database!");
})
.catch((error) => {
    console.log("Connection failed!", error);
});
响应:
[nodemon] starting `node server.js`
Connection failed! { MongoNetworkError: failed to connect to server 
[cluster0-shard-00-01-efzkv.mongodb.net:27017] on first connect 
[MongoNetworkError: getaddrinfo ENOTFOUND cluster0-shard-00-01- 
efzkv.mongodb.net cluster0-shard-00-01-efzkv.mongodb.net:27017]
at Pool.<anonymous> (/Users/Travis/Desktop/Github_Repos/OMNI-INC/Omni- 
pl/node_modules/mongodb-core/lib/topologies/server.js:564:11)
at Pool.emit (events.js:182:13)
at Connection.<anonymous> (/Users/Travis/Desktop/Github_Repos/OMNI-INC/Omni- 
pl/node_modules/mongodb-core/lib/connection/pool.js:317:12)
at Object.onceWrapper (events.js:273:13)
at Connection.emit (events.js:182:13)
at TLSSocket.<anonymous> (/Users/Travis/Desktop/Github_Repos/OMNI-INC/Omni- 
pl/node_modules/mongodb-core/lib/connection/connection.js:246:50)
at Object.onceWrapper (events.js:273:13)
at TLSSocket.emit (events.js:182:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at …mean-stack ×10
node.js ×7
angularjs ×4
express ×4
mongodb ×3
angular ×2
javascript ×2
mongoose ×2
typescript ×2
express-jwt ×1
gulp ×1
jwt ×1
socket.io ×1
ubuntu ×1