mirror of
/repos/Prototyper.git
synced 2025-12-30 06:31:32 +01:00
work in progress
This commit is contained in:
parent
7d928486fe
commit
fbcd46801b
79
server.js
79
server.js
@ -3,6 +3,10 @@ process.title = 'Prototyper';
|
||||
|
||||
var connect = require('connect');
|
||||
var express = require('express');
|
||||
var passport = require('passport');
|
||||
var LocalStrategy = require('passport-local').Strategy;
|
||||
var ConnectRoles = require('connect-roles');
|
||||
var MongoClient = require('mongodb').MongoClient;
|
||||
var rethink = require('rethinkdb');
|
||||
var addRoutes = require('./lib/routes.js');
|
||||
var shareServer = require('./lib/share.js');
|
||||
@ -76,7 +80,7 @@ var config = {
|
||||
server: 'mongodb://localhost:27017/Prototyper',
|
||||
options: {
|
||||
db: {
|
||||
native_parser: true,
|
||||
native_parser: false,
|
||||
fsync: true
|
||||
},
|
||||
server: {
|
||||
@ -116,7 +120,7 @@ var config = {
|
||||
}
|
||||
}
|
||||
},
|
||||
sockjs_url: 'https://cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js'
|
||||
sockjs_url: 'https://d1fxtkz8shb9d2.cloudfront.net/sockjs-0.3.4.min.js'
|
||||
},
|
||||
staticpath: '/lib/share',
|
||||
db: {type: 'none'}
|
||||
@ -131,7 +135,13 @@ var config = {
|
||||
preview: '/page',
|
||||
importer: '/importer'
|
||||
},
|
||||
statics: {
|
||||
users: {
|
||||
admin: {
|
||||
password: 'admin',
|
||||
roles: 'admin'
|
||||
}
|
||||
},
|
||||
statics: {
|
||||
dev_favicon_path: __dirname + '/public/favicon_dev.ico',
|
||||
importer_path: __dirname + '/public',
|
||||
public_path: __dirname + '/public',
|
||||
@ -145,6 +155,7 @@ var config = {
|
||||
config.debug && config.debug('config loaded');
|
||||
|
||||
var app = express();
|
||||
var roles = new ConnectRoles();
|
||||
|
||||
express.static.mime.define({
|
||||
'text/css': ['css', 'less']
|
||||
@ -162,6 +173,27 @@ if (process.env.DEBUG) {
|
||||
//noinspection JSUnresolvedFunction
|
||||
app.use(express.compress());
|
||||
|
||||
//noinspection JSUnresolvedFunction
|
||||
app.use(express.cookieParser());
|
||||
//noinspection JSUnresolvedFunction
|
||||
app.use(express.bodyParser());
|
||||
//noinspection JSUnresolvedFunction
|
||||
// app.use(express.session({ secret: 'keyboard cat' }));
|
||||
//noinspection JSUnresolvedFunction
|
||||
app.use(passport.initialize());
|
||||
//noinspection JSUnresolvedFunction
|
||||
//app.use(passport.session());
|
||||
//noinspection JSUnresolvedFunction
|
||||
app.use(roles.middleware());
|
||||
|
||||
app.post('/login',
|
||||
passport.authenticate('local', {
|
||||
session: false,
|
||||
successRedirect: '/editor.html',
|
||||
failureRedirect: '/login.html',
|
||||
failureFlash: false })
|
||||
);
|
||||
|
||||
if (!process.env.NODE_ENV) {
|
||||
app.get('/favicon.ico', function (req, res) {
|
||||
res.sendfile(config.statics.dev_favicon_path, null, null);
|
||||
@ -183,6 +215,16 @@ config.debug && config.debug('static routes set');
|
||||
var markerInstance = markers(config);
|
||||
var helperInstance = helpers(markerInstance);
|
||||
|
||||
//MongoClient.connect(config.mongo.server, config.mongo.options, function connection(err, db) {
|
||||
// if (err) {
|
||||
// config.error && config.error('ERR connection to database', err);
|
||||
// return process.exit(3);
|
||||
// }
|
||||
// function exit(code) {
|
||||
// db.close();
|
||||
// process.exit(code);
|
||||
// }
|
||||
|
||||
rethink.connect(config.rethink.server, function connection_result(err, connection) {
|
||||
|
||||
if (err) {
|
||||
@ -202,6 +244,35 @@ rethink.connect(config.rethink.server, function connection_result(err, connectio
|
||||
|
||||
config.debug && config.debug('database connected');
|
||||
|
||||
passport.unuse("session");
|
||||
|
||||
passport.use(new LocalStrategy({ passReqToCallback: true},
|
||||
function(req, username, password, done) {
|
||||
config.error('check user',username, password);
|
||||
if (config.users[username]) {
|
||||
var user = config.users[username];
|
||||
config.error(user);
|
||||
if (user.password === password) {
|
||||
return done(null, user);
|
||||
}
|
||||
return done(null, false, {message: 'Incorrect password.'});
|
||||
} else {
|
||||
User.findOne({username: username}, function (err, user) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
if (!user) {
|
||||
return done(null, false, {message: 'Incorrect username.'});
|
||||
}
|
||||
if (!user.validPassword(password)) {
|
||||
return done(null, false, {message: 'Incorrect password.'});
|
||||
}
|
||||
return done(null, user);
|
||||
});
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
//Create the database if needed.
|
||||
rethink.dbList().contains(config.rethink.server.db).do(function (containsDb) {
|
||||
return rethink.branch(
|
||||
@ -224,6 +295,7 @@ rethink.connect(config.rethink.server, function connection_result(err, connectio
|
||||
|
||||
var updateShare = updateShareDocument(config, model);
|
||||
var dataBaseInstance = rethinkData(config, rethink, connection);
|
||||
// var dataBaseInstance = mongoData(config, db, model);
|
||||
var dataInstance = dataAccessor(config, dataBaseInstance, updateShare);
|
||||
|
||||
config.debug && config.debug('dataInstance initialized');
|
||||
@ -272,7 +344,6 @@ rethink.connect(config.rethink.server, function connection_result(err, connectio
|
||||
return config.info && config.info('Server running at http://127.0.0.1:' + config.port);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user