小编luk*_*paw的帖子

angularjs nodejs app的最佳部署架构

我在angularjs和nodejs中有Moto Adverts应用程序.Angularjs-client-side在Apache HTTP Server(localhost:8000)上运行,但nodejs-server-side以node.js http server(localhost:3000)运行.

一块客户端代码(angularjs):

var motoAdsServices = angular.module('motoAdsServices', ['ngResource']);

motoAdsServices.factory('Brand', ['$resource', function($resource) {
    return $resource('http://localhost\\:3000/api/:id', {}, {
      query: {
        method: 'GET',
        params: {
          id: 'brands'
        },
        isArray: true
      }
    });
  }]);
Run Code Online (Sandbox Code Playgroud)

一块服务器端代码(nodejs):

var express = require('express');
var path = require('path');
var http = require('http');
var brands = require('./routes/brands');

var app = express();

var allowCrossDomain = function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "X-Requested-With");
  next();
};

app.configure(function() {
  app.set('port', process.env.PORT || 3000);
  app.use(express.logger('dev'));  /* 'default', 'short', 'tiny', 'dev' …
Run Code Online (Sandbox Code Playgroud)

node.js angularjs

13
推荐指数
3
解决办法
8224
查看次数

为什么历史记录不能用于Firefox中的<a> onclick?

我不明白为什么在Firefox window.history.back()中可以使用按钮:

<button onclick="window.history.back()">Go back</button>
Run Code Online (Sandbox Code Playgroud)

但它不适用于链接:

<a onclick="window.history.back()">Go back</a>
Run Code Online (Sandbox Code Playgroud)

有什么不同?

举例说明:

的index.html

<!DOCTYPE html>
<html>
<body>
  <h1>First page</h1>
  <br/>
  <a href="second.html">Second</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

second.html

<!DOCTYPE html>
<html>
<body>
  <h1>Second page</h1>
  <a href="third.html">Third</a>
  <br/>
  <br/>
  <button onclick="window.history.back()">Go Back (button)</button>
  <br/>
  <a href="javascript: void(0);" onclick="window.history.back()">Go Back (a)</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

third.html

<!DOCTYPE html>
<html>
<body>
  <h1>Third page</h1>
  <br/>
  <button onclick="window.history.back()">Go Back (button)</button>
  <br/>
  <a href="javascript: void(0);" onclick="window.history.back()">Go Back (a)</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

场景:

  1. 运行index.html并单击Second.
  2. 在second.html上单击第三个.
  3. 在third.html上单击返回(a).
  4. 在second.html上单击 …

html javascript

8
推荐指数
1
解决办法
2万
查看次数

当角度应用程序呼叫休息服务时,为什么端口号被切断

我有休息服务:

http://localhost:3000/api/brands
Run Code Online (Sandbox Code Playgroud)

当我从网络浏览器测试它时效果很好.

我在角度服务中使用它:

var motoAdsServices = angular.module('motoAdsServices', ['ngResource']);

motoAdsServices.factory('Brand', ['$resource', function($resource) {
    return $resource('http://localhost:3000/api/:id', {}, {
      query: {
        method: 'GET',
        params: {
          id: 'brands'
        },
        isArray: true
      }
    });
  }]);
Run Code Online (Sandbox Code Playgroud)

当它被调用时我有错误,因为在reqest URL中我没有端口号:

Request URL: http://localhost/api/brands
Run Code Online (Sandbox Code Playgroud)

为什么端口数字被削减?角切呢?

Angular doc中写道:

参数化的URL模板,其参数前缀为:in/user /:username.如果您使用的是带有端口号的URL(例如http://example.com:8080/api),则会受到尊重.

UPDATE

我使用角度版本1.0.8(感谢@KayakDave供你注意),但Angular doc适用于版本1.2.

rest angularjs

5
推荐指数
1
解决办法
5479
查看次数

标签 统计

angularjs ×2

html ×1

javascript ×1

node.js ×1

rest ×1