More work stuffs

This commit is contained in:
Dobie Wollert
2014-10-07 03:25:36 -07:00
parent 0a7ad61eb4
commit 060fdbde29
6 changed files with 79 additions and 16 deletions

View File

@ -103,18 +103,24 @@ function startExpress() {
app.use(require('connect-livereload')());
/*
app.use('/api', express.static(__dirname + '/demo', {
index: ['index.json']
}));
app.use('/demo', express.static(__dirname + '/demo'));
app.use(express.static('build'));
*/
/*
app.all('/api/*', function(req, res) {
var url = 'http://localhost:8080' + req.url;
var url = 'http://new.atlb.co/' + req.url;
req.pipe(request(url)).pipe(res);
});
*/
app.all('/images/*', function(req, res) {
var url = 'http://new.atlb.co/' + req.url;
req.pipe(request(url)).pipe(res);
});
app.use(express.static('build'));
app.all('/*', function(req, res) {
res.sendFile('index.html', { root: 'build' });

View File

@ -1,6 +1,7 @@
<img ng-src="{{post.header}}">
<img ng-show="post.image" ng-src="/images/{{post.image}}">
<div class="title">{{post.title}}</div>
<div class="body">{{post.body}}</div>
<div ng-hide="post.details" class="preview">{{post.preview}}</div>
<div class="details">{{post.details}}</div>
<div class="images">
<img ng-repeat="image in images track by $index" ng-src="{{image}}">
<img ng-repeat="image in gallery track by $index" ng-src="/images/{{image}}">
</div>

View File

@ -7,8 +7,8 @@ angular.module('biomed-frontend', [
])
.factory('Posts', function($resource) {
return $resource('/api/:id',
{ id: '@id' }
return $resource('/api/v1/posts/:_id',
{ '_id': '@_id' }
);
})
.config(function($urlRouterProvider, $locationProvider) {
@ -25,25 +25,34 @@ angular.module('biomed-frontend', [
templateUrl: 'app/list.html',
resolve: {
posts: function(Posts) {
return Posts.query();
return Posts.query({
'status': 'posted',
'sort': '-createdOn',
});
}
},
controller: function($scope, posts, $timeout) {
$scope.posts = posts;
$scope.showMore = function(post) {
return post.details || post.gallery.length > 0;
}
}
})
.state('site.details', {
url: '/posts/:id',
url: '/posts/:_id',
templateUrl: 'app/details.html',
resolve: {
post: function(Posts, $stateParams) {
return Posts.get($stateParams);
return Posts.get({
'_id': $stateParams._id
});
}
},
controller: function($scope, post) {
post.$promise.then(function() {
$scope.post = post;
$scope.images = post.images;
$scope.gallery = post.gallery;
});
}
});

View File

@ -2,12 +2,12 @@
<div ng-repeat="post in posts" class="masonry-brick">
<div class="box col3">
<div class="thumbnail">
<img class="img-rounded" ng-src="{{post.image}}">
<img class="img-rounded" ng-show="post.image" ng-src="/images/{{post.image}}">
<div class="caption text-center">
<h3>{{post.title}}</h3>
<p>{{post.body}}</p>
<p>{{post.preview}}</p>
<p>
<a ui-sref="site.details(post)" ng-show="post.more" class="btn btn-default" role="button">Read More</a>
<a ui-sref="site.details(post)" ng-show="showMore(post)" class="btn btn-default" role="button">Read More</a>
</p>
</div>
</div>

View File

@ -0,0 +1,12 @@
{
"name": "biomed-webserver",
"version": "0.0.1",
"devDependencies": {},
"dependencies": {
"express": "~4.9.5",
"body-parser": "~1.9.0",
"method-override": "~2.2.0",
"mongoose": "~3.8.17",
"express-restify-mongoose": "~0.6.10"
}
}

View File

@ -0,0 +1,35 @@
var http = require('http');
var express = require('express');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var restify = require('express-restify-mongoose');
mongoose.connect('mongodb://localhost/biomed');
var Post = new Schema({
title: { type: String },
preview: { type: String },
details: { type: String },
image: { type: String },
gallery: [
{ type: String }
],
status: { type: String }
});
var PostModel = mongoose.model('Post', Post);
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(methodOverride());
restify.serve(app, PostModel, {
prereq: function(req) {
return req.method === 'GET';
}
});
http.createServer(app).listen(3000, function() {
console.log('Express server listening on port 3000');
});