Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekbh committed Feb 22, 2012
0 parents commit 99f309b
Show file tree
Hide file tree
Showing 659 changed files with 101,312 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README
@@ -0,0 +1,3 @@
WIP

ThreatWiki API with a nodejs, express, mongoose, mongo stack
121 changes: 121 additions & 0 deletions app.js
@@ -0,0 +1,121 @@
var application_root = __dirname,
express = require("express"),
routes = require("./routes"),
path = require("path"),
mongoose = require('mongoose');

var app = module.exports = express.createServer();

// Database
mongoose.connect('mongodb://localhost/namp');

// Config
app.configure(function () {
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(application_root, "public")));
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
app.use(express.errorHandler());
});

// Schema

var Schema = mongoose.Schema;

var Soc = new Schema({
title: { type: String, required: true },
description: { type: String, required: false },
modified: { type: Date, default: Date.now }
});

// BusinessLogic
var SocModel = mongoose.model('Soc', Soc);

// Server Routing
app.get('/', routes.index);

// read a list
app.get('/api/soc', function (req, res){
return SocModel.find(function (err, socs) {
if (!err) {
return res.send(socs);
} else {
return console.log(err);
}
});
});

// create single
app.post('/api/soc', function (req, res){
var soc1;
console.log("POST: ");
console.log(req.body);

soc1 = new SocModel({
title: req.body.title,
description: req.body.description
});

product.save(function (err) {
if (!err) {
return console.log("created");
} else {
return console.log(err);
}
});
return res.send(soc);
});

// read by id
app.get('/api/soc/:id', function (req, res){
return SocModel.findById(req.params.id, function (err, soc1) {
if (!err) {
return res.send(soc1);
} else {
return console.log(err);
}
});
});

// update
app.put('/api/soc/:id', function (req, res){
return SocModel.findById(req.params.id, function (err, soc1) {
soc1.title = req.body.title;
soc2.description = req.body.description;
return soc1.save(function (err) {
if (!err) {
console.log("updated");
} else {
console.log(err);
}
return res.send(product);
});
});
});

// delete by id
app.delete('/api/products/:id', function (req, res){
return ProductModel.findById(req.params.id, function (err, product) {
return product.remove(function (err) {
if (!err) {
console.log("removed");
return res.send('');
} else {
console.log(err);
}
});
});
});

// Launch Server
app.listen(3000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);

1 change: 1 addition & 0 deletions node_modules/.bin/express

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/jade

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/express/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 99f309b

Please sign in to comment.