Browse Source

you know what? screw node

master
Julio Biason 11 years ago
parent
commit
30d3587c30
  1. 7
      .gitignore
  2. 20
      LICENSE
  3. 70
      app.js
  4. 9
      bin/www
  5. 34
      models/index.js
  6. 21
      models/users.js
  7. 17
      package.json
  8. 4
      routes/index.js
  9. 4
      routes/user.js

7
.gitignore vendored

@ -6,10 +6,3 @@ lib-cov
*.out *.out
*.pid *.pid
*.gz *.gz
pids
logs
results
npm-debug.log
node_modules

20
LICENSE

@ -1,20 +0,0 @@
The MIT License (MIT)
Copyright (c) 2014 Julio Biason
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

70
app.js

@ -1,70 +0,0 @@
var express = require('express');
var http = require('http');
var path = require('path');
var favicon = require('static-favicon');
var logger = require('morgan');
var bodyParser = require('body-parser');
var routes = require('./routes');
var users = require('./routes/user');
var db = require('./models');
var app = express();
app.use(favicon());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
// app.use(cookieParser());
app.use(app.router);
/// catch 404 and forwarding to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
/// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;
// routes
app.get('/', routes.index);
// database and start up
db
.sequelize
.sync({ force: true })
.complete(function (err) {
if (err) {
throw err;
}
port = app.get('port') || 3000;
http.createServer(app).listen(port, function () {
console.log('Express server listening on port ' + port);
});
});

9
bin/www

@ -1,9 +0,0 @@
#!/usr/bin/env node
var debug = require('debug')('my-application');
var app = require('../app');
app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
});

34
models/index.js

@ -1,34 +0,0 @@
// Taken directly from Sequelize documentation
var fs = require('fs'),
path = require('path'),
Sequelize = require('sequelize-sqlite').sequelize,
sqlite = require('sequelize-sqlite').sqlite,
lodash = require('lodash'),
db = {};
var sequelize = new Sequelize('database', 'username', null, {
dialect: 'sqlite',
storage: './luncho.sq'
});
fs
.readdirSync(__dirname)
.filter(function(file) {
return (file.indexOf('.') !== 0) && (file !== 'index.js');
})
.forEach(function(file) {
var model = sequelize.import(path.join(__dirname, file));
db[model.name] = model;
});
Object.keys(db).forEach(function(modelName) {
if ('associate' in db[modelName]) {
db[modelName].associate(db);
}
});
module.exports = lodash.extend({
sequelize: sequelize,
Sequelize: Sequelize
}, db);

21
models/users.js

@ -1,21 +0,0 @@
module.exports = function(sequelize, DataTypes) {
var User = sequelize.define('User', {
username: DataTypes.STRING,
passhash: DataTypes.STRING,
token: DataTypes.STRING, // this forces only one hash per user
issuedDate: DataTypes.DATE // since tokens are one way only, we need to make sure the token is valid for today
}, {
classMethods: {
userToken: function (reqToken, next) {
User.find({ token: reqToken }).success(user) {
// check if the token is valid for today
if (next) {
next (user);
}
}
}
}
});
return User;
};

17
package.json

@ -1,17 +0,0 @@
{
"name": "Lunch-o",
"version": "0.1.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"express": "~3.4.8",
"static-favicon": "~1.0.0",
"morgan": "~1.0.0",
"body-parser": "~1.0.0",
"debug": "~0.7.4",
"sequelize-sqlite": "",
"lodash": ""
}
}

4
routes/index.js

@ -1,4 +0,0 @@
/* GET home page. */
exports.index = function(req, res){
res.send({"status": "ERROR", "error": "No index method, go away"});
};

4
routes/user.js

@ -1,4 +0,0 @@
/* GET users listing. */
exports.list = function(req, res){
res.send('respond with a resource');
};
Loading…
Cancel
Save