|
|
@@ -10,8 +10,7 @@ var common = require ('./server/common'), |
|
|
|
dbs = require ('./server/dbs'), |
|
|
|
files = require ('./server/files'); |
|
|
|
*/ |
|
|
|
|
|
|
|
const fs = require ('fs'), |
|
|
|
var fs = require ('fs'), |
|
|
|
http = require ('http'), |
|
|
|
https = require ('https'), |
|
|
|
express = require ('express'), |
|
|
@@ -20,7 +19,7 @@ const fs = require ('fs'), |
|
|
|
//serveFavicon = require ('serve-favicon'), |
|
|
|
bodyParser = require ('body-parser'); |
|
|
|
//MongoStore = require ('connect-mongo')(session); // uss mongodb as session storage |
|
|
|
const Message = require('./message.model.js'); |
|
|
|
var Message = require('./message.model.js'); |
|
|
|
|
|
|
|
var app = express(); |
|
|
|
|
|
|
@@ -74,33 +73,34 @@ app.use (bodyParser.urlencoded({extended: true})); |
|
|
|
//var api_routes = express.Router(); // express app-object routing |
|
|
|
//app.use ('/api', api_routes); |
|
|
|
|
|
|
|
app.use (function (req,res,done) { |
|
|
|
console.log (req.url); |
|
|
|
app.use (function (req, res, done) { |
|
|
|
console.log(req.url); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
|
|
|
|
//global.__basedir = __dirname; |
|
|
|
|
|
|
|
// Static Files |
|
|
|
app.use (express.static(__dirname + '/public')); // Allow server access to 'public' folder |
|
|
|
app.use(express.static(__dirname + '/public')); // Allow server access to 'public' folder |
|
|
|
|
|
|
|
//app.use(express.static('resources')); |
|
|
|
|
|
|
|
// Configuring the database |
|
|
|
const dbConfig = require('./mongodb.config.js'); |
|
|
|
const mongoose = require('mongoose'); |
|
|
|
var dbConfig = require('./mongodb.config.js'); |
|
|
|
var mongoose = require('mongoose'); |
|
|
|
|
|
|
|
mongoose.Promise = global.Promise; |
|
|
|
|
|
|
|
// Connecting to the database |
|
|
|
mongoose.connect(dbConfig.url, {useNewUrlParser: true}) |
|
|
|
.then(() => { |
|
|
|
//mongoose.connect(`mongodb://${server}/${dbConfig.url}`) |
|
|
|
mongoose.connect(dbConfig.url, {useNewUrlParser: true}).then(() => { |
|
|
|
console.log("Successfully connected to MongoDB."); |
|
|
|
}).catch(err => { |
|
|
|
console.log('Could not connect to MongoDB.'); |
|
|
|
process.exit(); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
//require('./app/routes/message.route.js')(app); |
|
|
|
|
|
|
|
app.get ('/api/ids', function (req, res) { |
|
|
@@ -131,6 +131,18 @@ app.get ("/api/msg/:id", function (req, res) { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
/*app.get ("/api/msg/search/:phrase", function (req, res) { |
|
|
|
Message.find ({$text: {$search: req.params.phrase}) .then (function (err, results){ |
|
|
|
if (err) { |
|
|
|
console.log (err); |
|
|
|
res .status(404) .json (err); |
|
|
|
} else { |
|
|
|
console.log(JSON.stringify(results)); |
|
|
|
res.json(results); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
*/ |
|
|
|
/*function makeid() { |
|
|
|
var text = ""; |
|
|
|
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |