Skip to content

Instantly share code, notes, and snippets.

View mockra's full-sized avatar

David Ratajczak mockra

View GitHub Profile
@mockra
mockra / server.js
Last active December 31, 2015 21:59
var express = require('express');
var mongoose = require('mongoose');
var path = require('path');
var app = express();
mongoose.set('debug', true);
// This is the location of your mongo server, as well as the db name.
mongoose.connect('mongodb://127.0.0.1/express_ember_example');
app.set('port', process.env.PORT || 3333);
@mockra
mockra / todo.js
Last active January 1, 2016 11:59
var mongoose = require('mongoose');
var todoSchema = new mongoose.Schema({
title: { type: String, required: true },
is_completed: Boolean
});
module.exports = mongoose.model('Todo', todoSchema);
var todos = require('./controllers/todos');
module.exports = function(app) {
app.get('/api/1/todos', todos.index);
app.post('/api/1/todos', todos.create);
app.put('/api/1/todos/:id', todos.update);
app.del('/api/1/todos/:id', todos.destroy);
};
var express = require('express');
var mongoose = require('mongoose');
var path = require('path');
var app = express();
mongoose.set('debug', true);
mongoose.connect('mongodb://127.0.0.1/express_ember_example');
app.set('port', process.env.PORT || 3333);
app.use(express.logger('dev'));
var Todo = require('../models/todo');
exports.index = function(req, res) {
Todo.find(function(err, todos) {
res.send({
todos: todos
});
});
};
App.TodosController = Ember.ArrayController.extend({
actions: {
createTodo: function () {
// Get the todo title set by the "New Todo" text field
var title = this.get('newTitle');
if (!title.trim()) { return; }
// Create the new Todo model
var todo = this.store.createRecord( App.Todo, {
title: title,
App.TodosRoute = Ember.Route.extend({
model: function () {
return this.store.find('todo');
}
});
App.TodosIndexRoute = Ember.Route.extend({
model: function () {
return this.modelFor('todos');
}
DS.RESTAdapter.reopen({
host: 'https://api.example.com'
// OR
url: 'https://api.example.com'
});
Ember.Application.initializer({
name: 'authentication',
initialize: function(container, application) {
Ember.SimpleAuth.setup(container, application);
}
});
App.ApplicationRoute = Ember.Route.extend(Ember.SimpleAuth.ApplicationRouteMixin);
App.Router.map(function() {
this.resource('todos', { path: '/' }, function() {
this.route('active');
this.route('completed');
});
});