Php AngularJS应用程序在Chrome上运行时出现错误连接被拒绝
我正在使用cg Angular generator创建Angular应用程序,该生成器将phalcon作为后端。我使用configureProxies连接后端和前端。我的Gruntfile.js是 Grunfile.jsPhp AngularJS应用程序在Chrome上运行时出现错误连接被拒绝,php,angularjs,apache,google-chrome,Php,Angularjs,Apache,Google Chrome,我正在使用cg Angular generator创建Angular应用程序,该生成器将phalcon作为后端。我使用configureProxies连接后端和前端。我的Gruntfile.js是 Grunfile.js /*jslint节点:true*/ "严格使用",; var pkg=require('./package.json'); var createFolderGlobs=函数(fileTypePatterns){ fileTypePatterns=Array.isArray(fi
/*jslint节点:true*/
"严格使用",;
var pkg=require('./package.json');
var createFolderGlobs=函数(fileTypePatterns){
fileTypePatterns=Array.isArray(fileTypePatterns)?fileTypePatterns:[fileTypePatterns];
var ignore=['node_modules','bower_components','dist','temp'];
var fs=需要('fs');
返回fs.readdirSync(process.cwd())
.map(函数(文件){
if(忽略.indexOf(文件)!=-1||
file.indexOf('.')==0||
!fs.lstatSync(文件).isDirectory()){
返回null;
}否则{
返回fileTypePatterns.map(函数(模式){
返回文件+'/**/'+模式;
});
}
})
.过滤器(功能(模式){
返回模式;
})
.concat(文件类型模式);
};
module.exports=函数(grunt){
要求('load-grunt-tasks')(grunt);
grunt.initConfig({
连接:{
代理:[{
上下文:['/'],
主持人:“0.0.0.0”,
港口:80,
https:false,
更改来源:正确
}],
主要内容:{
选项:{
港口:9001,
主机名:“0.0.0.0”,
目录:'.',
利弗雷罗德:35730
}
},
利弗雷罗德:{
选项:{
中间件:功能(连接、选项){
if(!Array.isArray(options.base)){
options.base=[options.base];
}
//设置代理
var middleware=[require('grunt-connect-proxy/lib/utils').proxyRequest];
//提供静态文件。
options.base.forEach(函数(基){
中间件。推送(连接。静态(基础));
});
//使目录可浏览。
var directory=options.directory | | options.base[options.base.length-1];
push(connect.directory(directory));
退货;
}
}
}
},
观察:{
主要内容:{
选项:{
利弗雷罗德:35730,
LivereloadError:错误,
产卵:假
},
文件:[createFolderGlobs(['*.js','*.less','*.html']),'!\u SpecRunner.html','!.grunt'],
tasks:[]//在监视事件处理程序期间动态运行所有任务
}
},
jshint:{
主要内容:{
选项:{
jshintrc:“.jshintrc”
},
src:createFolderGlobs('*.js')
}
},
清洁:{
之前:{
src:['dist','temp']
},
之后:{
src:['temp']
}
},
减:{
制作:{
选项:{
},
档案:{
“temp/app.css”:“app.less”
}
}
},
NGB模板:{
主要内容:{
选项:{
模块:pkg.name,
htmlmin:'
},
src:[createFolderGlobs('*.html')、'!index.html'、'!\u SpecRunner.html'],
dest:'temp/templates.js'
}
},
副本:{
主要内容:{
档案:[
{src:['img/**',dest:'dist/'},
{src:['bower_components/font awesome/font/**',dest:'dist/',filter:'isFile',expand:true},
{src:['bower_components/bootstrap/font/**',dest:'dist/',filter:'isFile',expand:true}
//{src:['bower_components/angular ui-utils/ui-utils-iesiv.min.js'],dest:'dist/'},
//{src:['bower_components/select2/*.png','bower_components/select2/*.gif'],dest:'dist/css/',展平:真,展开:真},
//{src:['bower_components/angular mocks/angular mocks.js'],dest:'dist/'}
]
}
},
多姆·芒格:{
阅读:{
选项:{
阅读:[
{选择器:'script[data concat!=“false”]”,属性:'src',writeto:'appjs'},
{选择器:'link[rel=“stylesheet”][data concat!=“false”]”,属性:'href',writeto:'appcss'}
]
},
src:'index.html'
},
更新:{
选项:{
删除:['script[data remove!=“false”],'link[data remove!=“false”],
附加:[
{选择器:'body',html:'},
{选择器:'head',html:'}
]
},
src:'index.html',
dest:'dist/index.html'
}
},
cssmin:{
主要内容:{
src:['temp/app.css',''],
dest:'dist/app.full.min.css'
}
},
康卡特:{
主要内容:{
src:['','',
dest:'temp/app.full.js'
}
},
注:{
主要内容:{
src:'temp/app.full.js',
dest:'temp/app.full.js'
}
},
丑陋的:{
主要内容:{
src:'temp/app.full.js',
dest:'dist/app.full.min.js'
}
},
htmlmin:{
主要内容:{
选项:{
collapseBooleanAttributes:没错,
拼贴空白:对,
RemoveAttribute属性:对,
removeComments:对,
RemovemptyAttributes:没错,
removeScriptTypeAttributes:true,
removeStyleLinkTypeAttributes:true
},
档案:{
'dist/index.html':'dist/index.html'
}
}
},
业力:{
选项:{
框架:['jasmine'],
files:[//此文件数据也会在监视处理程序中更新,如果更新,也会在监视处理程序中更改
'',
'bower_components/angular mocks/angular mocks.js',
createFolderGlobs('*-spec.js')
],
日志级别:'错误',
记者:[摩卡咖啡],
autoWatch:false,//监视由grunt contrib watch处理
singleRun:对
},
所有测试:{
浏览器:['PhantomJS','Chrome','Firefox']
},
观察期间:{
浏览器:['PhantomJS']
},
}
});
registerTask('build'、['jshint'、'clean:before'、'less'、'dom_munger'、'ngtemplates'、'cssmin'、'ncat'、'ngAnnotate'、'uglify'、'copy'、'htmlmin'、'clean:after']);
registerTask('serve',['dom_munger:read','jshint','configureProxies:server','connect:livereload','watch']);
registerTask('test',['dom_munger:read','karma:all_tests');
grunt.event.on('watch',函数(操作,文件路径){
//https://github.com/gruntjs/grunt-contrib-watch/issues/156
var tasksToRun=[];
if(filepath.lastIndexOf('.js')!=-1&&filepath.lastIndexOf('.js')==filepath.length
/*jslint node: true */
'use strict';
var pkg = require('./package.json');
var createFolderGlobs = function(fileTypePatterns) {
fileTypePatterns = Array.isArray(fileTypePatterns) ? fileTypePatterns : [fileTypePatterns];
var ignore = ['node_modules','bower_components','dist','temp'];
var fs = require('fs');
return fs.readdirSync(process.cwd())
.map(function(file){
if (ignore.indexOf(file) !== -1 ||
file.indexOf('.') === 0 ||
!fs.lstatSync(file).isDirectory()) {
return null;
} else {
return fileTypePatterns.map(function(pattern) {
return file + '/**/' + pattern;
});
}
})
.filter(function(patterns){
return patterns;
})
.concat(fileTypePatterns);
};
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
connect: {
proxies: [{
context: ['/'],
host: '0.0.0.0',
port: 80,
https: false,
changeOrigin: true
}],
main: {
options: {
port: 9001,
hostname: '0.0.0.0',
directory: '.',
livereload: 35730
}
},
livereload: {
options: {
middleware: function(connect, options) {
if (!Array.isArray(options.base)) {
options.base = [options.base];
}
// Setup the proxy
var middlewares = [require('grunt-connect-proxy/lib/utils').proxyRequest];
// Serve static files.
options.base.forEach(function(base) {
middlewares.push(connect.static(base));
});
// Make directory browse-able.
var directory = options.directory || options.base[options.base.length - 1];
middlewares.push(connect.directory(directory));
return middlewares;
}
}
}
},
watch: {
main: {
options: {
livereload: 35730,
livereloadOnError: false,
spawn: false
},
files: [createFolderGlobs(['*.js','*.less','*.html']),'!_SpecRunner.html','!.grunt'],
tasks: [] //all the tasks are run dynamically during the watch event handler
}
},
jshint: {
main: {
options: {
jshintrc: '.jshintrc'
},
src: createFolderGlobs('*.js')
}
},
clean: {
before:{
src:['dist','temp']
},
after: {
src:['temp']
}
},
less: {
production: {
options: {
},
files: {
'temp/app.css': 'app.less'
}
}
},
ngtemplates: {
main: {
options: {
module: pkg.name,
htmlmin:'<%= htmlmin.main.options %>'
},
src: [createFolderGlobs('*.html'),'!index.html','!_SpecRunner.html'],
dest: 'temp/templates.js'
}
},
copy: {
main: {
files: [
{src: ['img/**'], dest: 'dist/'},
{src: ['bower_components/font-awesome/fonts/**'], dest: 'dist/',filter:'isFile',expand:true},
{src: ['bower_components/bootstrap/fonts/**'], dest: 'dist/',filter:'isFile',expand:true}
//{src: ['bower_components/angular-ui-utils/ui-utils-ieshiv.min.js'], dest: 'dist/'},
//{src: ['bower_components/select2/*.png','bower_components/select2/*.gif'], dest:'dist/css/',flatten:true,expand:true},
//{src: ['bower_components/angular-mocks/angular-mocks.js'], dest: 'dist/'}
]
}
},
dom_munger:{
read: {
options: {
read:[
{selector:'script[data-concat!="false"]',attribute:'src',writeto:'appjs'},
{selector:'link[rel="stylesheet"][data-concat!="false"]',attribute:'href',writeto:'appcss'}
]
},
src: 'index.html'
},
update: {
options: {
remove: ['script[data-remove!="false"]','link[data-remove!="false"]'],
append: [
{selector:'body',html:'<script src="app.full.min.js"></script>'},
{selector:'head',html:'<link rel="stylesheet" href="app.full.min.css">'}
]
},
src:'index.html',
dest: 'dist/index.html'
}
},
cssmin: {
main: {
src:['temp/app.css','<%= dom_munger.data.appcss %>'],
dest:'dist/app.full.min.css'
}
},
concat: {
main: {
src: ['<%= dom_munger.data.appjs %>','<%= ngtemplates.main.dest %>'],
dest: 'temp/app.full.js'
}
},
ngAnnotate: {
main: {
src:'temp/app.full.js',
dest: 'temp/app.full.js'
}
},
uglify: {
main: {
src: 'temp/app.full.js',
dest:'dist/app.full.min.js'
}
},
htmlmin: {
main: {
options: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
},
files: {
'dist/index.html': 'dist/index.html'
}
}
},
karma: {
options: {
frameworks: ['jasmine'],
files: [ //this files data is also updated in the watch handler, if updated change there too
'<%= dom_munger.data.appjs %>',
'bower_components/angular-mocks/angular-mocks.js',
createFolderGlobs('*-spec.js')
],
logLevel:'ERROR',
reporters:['mocha'],
autoWatch: false, //watching is handled by grunt-contrib-watch
singleRun: true
},
all_tests: {
browsers: ['PhantomJS','Chrome','Firefox']
},
during_watch: {
browsers: ['PhantomJS']
},
}
});
grunt.registerTask('build',['jshint','clean:before','less','dom_munger','ngtemplates','cssmin','concat','ngAnnotate','uglify','copy','htmlmin','clean:after']);
grunt.registerTask('serve', ['dom_munger:read','jshint','configureProxies:server', 'connect:livereload', 'watch']);
grunt.registerTask('test',['dom_munger:read','karma:all_tests']);
grunt.event.on('watch', function(action, filepath) {
//https://github.com/gruntjs/grunt-contrib-watch/issues/156
var tasksToRun = [];
if (filepath.lastIndexOf('.js') !== -1 && filepath.lastIndexOf('.js') === filepath.length - 3) {
//lint the changed js file
grunt.config('jshint.main.src', filepath);
tasksToRun.push('jshint');
//find the appropriate unit test for the changed file
var spec = filepath;
if (filepath.lastIndexOf('-spec.js') === -1 || filepath.lastIndexOf('-spec.js') !== filepath.length - 8) {
spec = filepath.substring(0,filepath.length - 3) + '-spec.js';
}
//if the spec exists then lets run it
if (grunt.file.exists(spec)) {
var files = [].concat(grunt.config('dom_munger.data.appjs'));
files.push('bower_components/angular-mocks/angular-mocks.js');
files.push(spec);
grunt.config('karma.options.files', files);
tasksToRun.push('karma:during_watch');
}
}
//if index.html changed, we need to reread the <script> tags so our next run of karma
//will have the correct environment
if (filepath === 'index.html') {
tasksToRun.push('dom_munger:read');
}
grunt.config('watch.main.tasks',tasksToRun);
});
};
connect: {
proxies: [{
context: ['/api'],
host: '0.0.0.0',
port: 80,
https: false,
changeOrigin: true
}],
//In here I remove the main:{}
options: {
port: 9001,
hostname: '0.0.0.0',
directory: '.',
livereload: 35730
},
livereload: {
options: {
middleware: function(connect, options) {
if (!Array.isArray(options.base)) {
options.base = [options.base];
}
// Setup the proxy
var middlewares = [require('grunt-connect-proxy/lib/utils').proxyRequest];
// Serve static files.
options.base.forEach(function(base) {
middlewares.push(connect.static(base));
});
// Make directory browse-able.
var directory = options.directory || options.base[options.base.length - 1];
middlewares.push(connect.directory(directory));
return middlewares;
}
}
}
},
grunt.registerTask('serve', ['configureProxies:server', 'connect:livereload','dom_munger:read','jshint', 'watch']);