简体   繁体   English

网站在本地工作/不在Openshift上运行(将本地,全局npm软件包版本与服务器,全局npm软件包版本同步)

[英]Site works locally / Not on Openshift (syncing local, global npm package versions with server, global npm package versions)

I am creating a forum with Angular - it interfaces with Node/Mongo, so there are plenty of requests that need to be executed to fill the page with the required data. 我正在使用Angular创建一个论坛-它与Node / Mongo交互,因此需要执行很多请求才能用所需的数据填充页面。 Everything works exactly as it should locally, but when I upload to Openshift...the site seems to be very buggy, and it doesn't seem to execute more than half of the requests (if not all) or the requests I put in to make the forum function. 一切都在本地正常运行,但是当我上传到Openshift时...该网站似乎存在很多错误,并且似乎执行的请求(如果不是全部)或请求的一半以上使论坛发挥作用。

I am using a yeoman MEAN stack called angular-fullstack . 我使用的是yeoman MEAN堆栈称为angular-fullstack If you have yeoman you can create the seed with yo angular-fullstack . 如果您拥有yeoman ,则可以使用yo angular-fullstack创建种子。

The only things I had to change within that seed to get it to upload to openshift were: 我必须更改该种子中的唯一内容,才能将其上传到openshift:

server.js server.js

...

// Set default node environment to development
process.env.NODE_ENV = process.env.NODE_ENV || 'development';

...

to

...

// Set default node environment to development
process.env.NODE_ENV = process.env.NODE_ENV || 'production';

...

The above line refers to this code in lib/config/express.js: 上一行在lib / config / express.js中引用了以下代码:

if ('development' === env) {
  app.use(require('connect-livereload')());

  // Disable caching of scripts for easier testing
  app.use(function noCache(req, res, next) {
    if (req.url.indexOf('/scripts/') === 0) {
      res.header('Cache-Control', 'no-cache, no-store, must-revalidate');
      res.header('Pragma', 'no-cache');
      res.header('Expires', 0);
    }
    next();
  });

  app.use(express.static(path.join(config.root, '.tmp')));
  app.use(express.static(path.join(config.root, 'app')));
  app.set('views', config.root + '/app/views');
}

if ('production' === env) {
  app.use(compression());
  app.use(errorHandler());
  app.use(favicon(path.join(config.root, 'public', 'favicon.ico')));
  app.use(express.static(path.join(config.root, 'public')));
  app.set('views', config.root + '/views');
}

...

// Error handler - has to be last
if ('development' === app.get('env')) {
  app.use(errorHandler());
}

So let me know if you notice anything wrong with that production chunk of code - that is what is being run. 因此,如果您注意到该production代码段有什么问题,那就让我知道,这就是正在运行的代码。

Also, the Mongo URI needed to be changed to work with the MongoDB cartridge I set up on Openshift: 另外,需要更改Mongo URI才能与我在Openshift上设置的MongoDB盒一起使用:

mongo: {
uri: process.env.MONGOLAB_URI ||
     process.env.MONGOHQ_URL ||
     process.env.OPENSHIFT_MONGODB_DB_URL+process.env.OPENSHIFT_APP_NAME ||
     'mongodb://whateveritwas'
}

to

mongo: {
uri: process.env.MONGOLAB_URI ||
     process.env.MONGOHQ_URL ||
     process.env.OPENSHIFT_MONGODB_DB_URL+process.env.OPENSHIFT_APP_NAME ||
     'mongodb://admin:xxxxx@127.10.13.X:27017/hackabox' //the X's are to protect me
}

Initially to get it to upload to Openshift, you have to run yo angular-fullstack:openshift in the project folder, but I already did this, so now all I have to do to update my code on Openshift is: 最初,要使其上传到Openshift,必须在项目文件夹中运行yo angular-fullstack:openshift ,但是我已经这样做了,所以现在要做的就是在Openshift上更新我的代码:

  1. Go into the project folder in the console, and type grunt build (this creates the dist folder) 进入控制台中的项目文件夹,然后键入grunt build (这将创建dist文件夹)

  2. Change into the dist folder, add everything to git and run git push . 转到dist文件夹,将所有内容添加到git并运行git push

After that, I can go to the Openshift URL and see the site. 之后,我可以转到Openshift URL并查看该站点。

What is exactly happening now is (what I am focusing on) - is when you go to a page where you can view the post (it's contents, it's author, it's comments) - you can add comments, and they will show up initially because of how angular works...but when I navigate away, and come back...this code doesn't seem to execute as it should: 现在真正发生的是(我正在关注的)-是当您转到可以查看该帖子的页面时(它的内容,它的作者,它的评论)-您可以添加评论,并且它们最初会显示是因为角度的工作原理...但是当我导航离开并返回时...此代码似乎未按预期执行:

$scope.loadpost = function() {
  $http.get('/api/posts/'+$routeParams.id).success(function (data) {
    $scope.post = data;
    $scope.comments = $scope.post.comments;
    console.log('this is scope comments ' + $scope.comments);
    if($scope.comments[0] !== undefined) {
      $scope.commentstring.empty = '';
    }
  });
};

For testing purposes...I am calling it at the top of the post controller, like this: 出于测试目的...我在后控制器的顶部调用它,如下所示:

$scope.loadpost();

I am also using ng-init to call it when the page loads, like this: 我也在页面加载时使用ng-init调用它,如下所示:

<div ng-init="loadpost()">

THIS IS WHERE I GO INTO DETAIL ABOUT THE PROBLEM 这是我要详细说明问题的地方

I know this is redundant...but the point is...the function never gets called when the page loads...and all the post content that it needs to get from the database never arrives, because the request never happens - I can see that nothing happens in the console - and you can too, check out what I am talking about in the "Forum" section of my page - http://hackabox-eamonbenproject.rhcloud.com/forum . 我知道这是多余的...但是重点是...页面加载时永远不会调用该函数...并且从数据库获取所需的所有帖子内容都不会到达,因为请求永远不会发生-我可以看到控制台中什么都没有发生-您也可以在页面的“论坛”部分中查看我在说什么-http://hackabox-eamonbenproject.rhcloud.com/forum To post you will have to sign up as a user...and then you can see what I am talking about by going to the Forum, clicking on one of the posts...making a comment...and then navigating away and coming back...you don't have to make the comment, you will see that nothing shows up...but it will help you see the problem, because when the comment is created, a PUT request is supposed to happen which updates the post, but that never happens either...along with a bunch of GET requests that don't get called too. 要发布信息,您必须先以用户身份注册...然后您可以通过以下方式查看我在说什么:进入论坛,单击其中一则信息...发表评论...,然后浏览并回来...您不必发表评论,您将看不到任何内容...但是它将帮助您看到问题,因为创建评论时,应该会发生一个PUT请求,并进行更新帖子,但那也永远不会发生...以及一堆也不会被调用的GET请求。 Also, another thing, I noticed (at least once)...that if I do something in the forum...and then navigate to the "Settings" page, sometimes the logo goes away... 另外,我注意到(至少一次)...如果我在论坛中做某事...然后导航到“设置”页面,则有时徽标消失了...

I am starting to think that the minification process that goes on when I run grunt build is messing up the code...so that when it gets loaded to openshift, it becomes really buggy...but this is just a hunch - I guess to test my theory, I was wondering if there was anyway to upload to Openshift without minifying? 我开始认为运行grunt build时进行的缩小过程正在弄乱代码...因此当将其加载到openshift时,它会变得非常有bug ...但这只是预感-我猜为了检验我的理论,我想知道是否有没有缩小就上传到Openshift?

Thanks! 谢谢!

UPDATE UPDATE

As Pogrindis and I discussed this morning...there is an error in the node logs on openshift when a request is supposed to happen. 正如我今天和Pogrindis讨论的那样,当应该发生请求时,节点在openshift上登录时出错。 It says in the node logs that it is an Express error...and we realized that the global version for npm on openshift was using 3.2.5, while the seed I am using uses express v4.2.0 (and that is what I use globally, locally). 它在节点日志中说这是Express错误...并且我们意识到openshift上npm的全局版本正在使用3.2.5,而我正在使用的种子使用express v4.2.0(这就是我所使用的)全球,本地)。 I am in the process of downgrading my local, global express npm to 3.2.5 to see if this corrects the problem...but +1 to Pogrindis for teaching me about Node Version Manager...as well as having to possibly sync the versions of any npm package that is installed globally on Openshift! 我正在将本地的全球快车npm降级到3.2.5,以查看是否可以解决问题...但是向Pogrindis +1以便向我介绍节点版本管理器...以及必须同步在Openshift上全局安装的任何npm软件包的版本! Will keep everyone posted to make sure this resolves the problem! 将保持所有人的状态,以确保此问题得以解决!

Hard question to answer. 很难回答的问题。 A lot to look at. 有很多要看的。

Version-ing 版本-ING

Versions are huge in node, you could have a bad version and sh*t will hit the fan. 版本中的节点很大,您可能有一个错误的版本,并且可能会引起粉丝的注意。

There is an exceptional VERSION Saving github topic which comes to mind. 我想到了一个特别的VERSION Saving github主题。

If this is not the issue, you still need to keep in mind that its not a strongly types lang, that includes the versioning. 如果这不是问题,则仍然需要记住,它不是包含版本控制的强类型lang。

Each situation is different. 每种情况都不同。

https://github.com/npm/npm/issues/3417 https://github.com/npm/npm/issues/3417

This issue 'FIX' will kill a lot of users who have been using the previous(minor) version. 此问题“ FIX”将杀死使用先前(次要)版本的许多用户。 You need to be be specific with versioning. 您需要具体说明版本。 (i use this as an example) (我以此为例)

You will hit a lot of version issues with Node, as good as it is, unless you specify the version, it will get the latest version. Node会很好地解决很多版本问题,除非您指定版本,否则它将获得最新版本。

So, working on your local (3 months of hard sexy labor) machine means nothing unless in your packages you have a version specified. 因此,除非在软件包中指定了版本,否则在本地(经过3个月的辛苦劳动)机器上工作毫无意义。

Your server will only have the latest version. 您的服务器将仅具有最新版本。

From the question.. It can only BE a versioning problem. 从问题开始..只能是版本问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM