我的angular.js APP和我的express.js REST之间的沟通有问题.
我正在使用具有发电机角度0.7.1的yeoman 1.0.
我尝试使用中间件配置,grunt serve但我没有让它工作.
Angular App(端口:9000):
angular.module('wboxApp')
.controller('AdminCtrl', function ($scope, $routeParams, $http, fbRef) {
var ref = fbRef();
var token = $routeParams.token;
$http.post('http://127.0.0.1:3000/box/token/get', {token: token}).success(function (data) {
console.log(data);
}
});
});
Run Code Online (Sandbox Code Playgroud)
Express API(端口:3000):
app.post('/box/token/get', function (req, res) {
res.header('Access-Control-Allow-Origin', req.headers.origin || "*");
res.header('Access-Control-Allow-Methods', 'GET,POST,PUT,HEAD,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'content-Type,x-requested-with');
var token = req.body.token;
var tokenRef = ref.child('tokens').child(token);
tokenRef.once('value', function (data) {
var fullToken = data.val();
fullToken = fullToken + '.' + token;
if (data.val()) {
res.json({fullToken: fullToken});
} …Run Code Online (Sandbox Code Playgroud) 对于http://127.0.0.1:9000/我得到的'/'()路线
不能获取 /
而对于我得到的/ v1路线
未找到
在此服务器上找不到请求的URL/v1.
这是我的Gruntfile.js:
// Generated on 2013-10-08 using generator-webapp 0.4.3
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
/*============================================
= Expose Prxy Function =
============================================*/
var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;
/*----- End of Expose Prxy Function ------*/
module.exports = function (grunt) {
// show elapsed time at the end
require('time-grunt')(grunt);
// load …Run Code Online (Sandbox Code Playgroud)