Skip to content

add simple ajax for table page and server for api with grunt-proxy #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,47 @@ module.exports = function (grunt) {
hostname: 'localhost',
livereload: 35729
},
proxies: [{
context: '/api', // the context of the data service
//context: '/data-service-path', // the context of the data service
host: 'localhost', // wherever the data service is running
port: 8080, // the port that the data service is running on
rewrite: {
// the key '^/api' is a regex for the path to be rewritten
// the value is the context of the data service
'^/api': '/data-service-path'
}
}],
livereload: {
options: {
open: true,
base: [
'.tmp',
'<%= yeoman.app %>',
'<%= yeoman.bower_components %>'
],
middleware: function (connect, options) {
console.log("option.base:"+options.base);
if (!Array.isArray(options.base)) {
options.base = [options.base];
console.log("option.base added:" +option.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;
}
/*
middleware: function (connect) {
return [
connect.static('.tmp'),
Expand All @@ -83,7 +121,7 @@ module.exports = function (grunt) {
),
connect.static(appConfig.app)
];
}
}*/
}
},
test: {
Expand All @@ -93,10 +131,7 @@ module.exports = function (grunt) {
return [
connect.static('.tmp'),
connect.static('test'),
connect().use(
'/bower_components',
connect.static('./bower_components')
),
//connect().use('/bower_components', connect.static('./bower_components') ), //removed for proxy
connect.static(appConfig.app)
];
}
Expand Down Expand Up @@ -374,6 +409,7 @@ module.exports = function (grunt) {
'clean:server',
'concurrent:server',
'autoprefixer',
'configureProxies:server',
'connect:livereload',
'watch'
]);
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ $ npm start
```sh
$ npm run dist
```

- open another shell and run server for ajax calls
```sh
cd serverapi/
node server.js
```

**Note:**
If you get this following error,
Expand All @@ -55,7 +59,8 @@ sudo chown -R [user name] ~/.config

## Roadmap

- Add sample AJAX calls and make the directives more modular
x Added sample AJAX calls for table
- make the directives more modular

### Automation tools

Expand Down
3 changes: 2 additions & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<!-- endbuild -->



<!--
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
Expand All @@ -51,6 +51,7 @@
ga('create', 'UA-XXXXX-X');
ga('send', 'pageview');
</script>
-->
<!-- Custom CSS -->

<!-- Custom Fonts -->
Expand Down
12 changes: 11 additions & 1 deletion app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ angular
'ui.router',
'ui.bootstrap',
'angular-loading-bar',
//'TableService',
])
.config(['$stateProvider','$urlRouterProvider','$ocLazyLoadProvider',function ($stateProvider,$urlRouterProvider,$ocLazyLoadProvider) {

Expand Down Expand Up @@ -127,7 +128,16 @@ angular
})
.state('dashboard.table',{
templateUrl:'views/table.html',
url:'/table'
url:'/table',
controller:'TableCtrl',
resolve: {
loadMyFile:function($ocLazyLoad) {
return $ocLazyLoad.load({
name:'sbAdminApp',
files:['scripts/controllers/tableContoller.js']
})
}
}
})
.state('dashboard.panels-wells',{
templateUrl:'views/ui-elements/panels-wells.html',
Expand Down
Loading