|
|
|
|
|
|
|
|
dbs = require ('./server/dbs'), |
|
|
dbs = require ('./server/dbs'), |
|
|
files = require ('./server/files'); |
|
|
files = require ('./server/files'); |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
const fs = require ('fs'), |
|
|
|
|
|
|
|
|
var fs = require ('fs'), |
|
|
http = require ('http'), |
|
|
http = require ('http'), |
|
|
https = require ('https'), |
|
|
https = require ('https'), |
|
|
express = require ('express'), |
|
|
express = require ('express'), |
|
|
|
|
|
|
|
|
//serveFavicon = require ('serve-favicon'), |
|
|
//serveFavicon = require ('serve-favicon'), |
|
|
bodyParser = require ('body-parser'); |
|
|
bodyParser = require ('body-parser'); |
|
|
//MongoStore = require ('connect-mongo')(session); // uss mongodb as session storage |
|
|
//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(); |
|
|
var app = express(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//var api_routes = express.Router(); // express app-object routing |
|
|
//var api_routes = express.Router(); // express app-object routing |
|
|
//app.use ('/api', api_routes); |
|
|
//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(); |
|
|
done(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
//global.__basedir = __dirname; |
|
|
//global.__basedir = __dirname; |
|
|
|
|
|
|
|
|
// Static Files |
|
|
// 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')); |
|
|
//app.use(express.static('resources')); |
|
|
|
|
|
|
|
|
// Configuring the database |
|
|
// 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; |
|
|
mongoose.Promise = global.Promise; |
|
|
|
|
|
|
|
|
// Connecting to the database |
|
|
// 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."); |
|
|
console.log("Successfully connected to MongoDB."); |
|
|
}).catch(err => { |
|
|
}).catch(err => { |
|
|
console.log('Could not connect to MongoDB.'); |
|
|
console.log('Could not connect to MongoDB.'); |
|
|
process.exit(); |
|
|
process.exit(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//require('./app/routes/message.route.js')(app); |
|
|
//require('./app/routes/message.route.js')(app); |
|
|
|
|
|
|
|
|
app.get ('/api/ids', function (req, res) { |
|
|
app.get ('/api/ids', 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() { |
|
|
/*function makeid() { |
|
|
var text = ""; |
|
|
var text = ""; |
|
|
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |
|
|
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |