diff options
author | madelinegr <laura_wilson@brown.edu> | 2019-02-14 02:47:28 -0500 |
---|---|---|
committer | madelinegr <laura_wilson@brown.edu> | 2019-02-14 02:47:28 -0500 |
commit | ddd503f21dc4b3368d80b4be475817cd9a13fcd1 (patch) | |
tree | 5a235f3405fb3c5e1c7bb9db852ef73ddbfb2b75 /src/server/index.ts | |
parent | ff25c29c6801b1858ce6cd15a5735dba1fc67e8c (diff) |
getting there?
Diffstat (limited to 'src/server/index.ts')
-rw-r--r-- | src/server/index.ts | 81 |
1 files changed, 51 insertions, 30 deletions
diff --git a/src/server/index.ts b/src/server/index.ts index 416eaa009..b81cdbcca 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -11,7 +11,7 @@ import { Socket } from 'socket.io'; import { Utils } from '../Utils'; import { ObservableMap } from 'mobx'; import { FIELD_ID, Field } from '../fields/Field'; -import { Database } from './database'; +// import { Database } from './database'; import { ServerUtils } from './ServerUtil'; import * as passportConfig from './authentication/config/passport'; import { getLogin, postLogin, getSignup, postSignup } from './authentication/controllers/user'; @@ -19,15 +19,50 @@ const config = require('../../webpack.config'); const compiler = webpack(config); const port = 1050; // default port to listen const serverPort = 1234; -import expressValidator = require('express-validator'); +import * as expressValidator from 'express-validator'; import expressFlash = require('express-flash'); -import bodyParser = require('body-parser'); +import * as bodyParser from 'body-parser'; +import * as session from 'express-session'; import c = require("crypto"); +const MongoStore = require('connect-mongo')(session); +const mongoose = require('mongoose'); +const bluebird = require('bluebird'); + +const mongoUrl = 'mongodb://localhost:27017/Dash'; +// mongoose.Promise = bluebird; +mongoose.connect(mongoUrl)//.then( +// () => { /** ready to use. The `mongoose.connect()` promise resolves to undefined. */ }, +// ).catch((err: any) => { +// console.log("MongoDB connection error. Please make sure MongoDB is running. " + err); +// process.exit(); +// }); +mongoose.connection.on('connected', function () { + console.log("connected"); +}) -app.use(bodyParser()); +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded({ extended: true })); app.use(expressValidator()); app.use(expressFlash()); -app.use(require('express-session')({ secret: `${c.randomBytes(64)}`, resave: true, saveUninitialized: true })); +app.use(require('express-session')({ + secret: `${c.randomBytes(64)}`, + resave: true, + saveUninitialized: true, + store: new MongoStore({ + url: 'mongodb://localhost:27017/Dash' + }) +})); +app.use(passport.initialize()); +app.use(passport.session()); +app.use((req, res, next) => { + res.locals.user = req.user; + next(); +}); + +app.get("/signup", getSignup); +app.post("/signup", postSignup); +app.get("/login", getLogin); +app.post("/login", postLogin); let FieldStore: ObservableMap<FIELD_ID, Field> = new ObservableMap(); @@ -69,7 +104,7 @@ server.on("connection", function (socket: Socket) { function barReceived(guid: String) { clients[guid.toString()] = new Client(guid.toString()); - Database.Instance.print() + // Database.Instance.print() } function addDocument(document: Document) { @@ -78,35 +113,21 @@ function addDocument(document: Document) { function setField(newValue: Transferable) { console.log(newValue._id) - if (Database.Instance.getDocument(newValue._id)) { - Database.Instance.update(newValue._id, newValue) - } - else { - Database.Instance.insert(newValue) - } + // if (Database.Instance.getDocument(newValue._id)) { + // Database.Instance.update(newValue._id, newValue) + // } + // else { + // Database.Instance.insert(newValue) + // } } function getField([fieldRequest, callback]: [GetFieldArgs, (field: Field) => void]) { let fieldId: string = fieldRequest.field - let result: string | undefined = Database.Instance.getDocument(fieldId) - if (result) { - let fromJson: Field = ServerUtils.FromJson(result) - } + // let result: string | undefined = Database.Instance.getDocument(fieldId) + // if (result) { + // let fromJson: Field = ServerUtils.FromJson(result) + // } } -// initialize passport -app.use(passport.initialize()); -app.use(passport.session()); - -app.use((req, res, next) => { - res.locals.user = req.user; - next(); -}); - -app.get("/signup", getSignup); -app.post("/signup", postSignup); -app.get("/login", getLogin); -app.post("/login", postLogin); - server.listen(serverPort); console.log(`listening on port ${serverPort}`);
\ No newline at end of file |