forked from o4oren/Ad-Hoc-Email-Server
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathahem.js
More file actions
45 lines (35 loc) · 1.3 KB
/
ahem.js
File metadata and controls
45 lines (35 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* Created by ogeva on 7/3/2017.
*/
'use strict';
const logger = require('./server/app/logger');
const fs = require('fs');
const path = require('path');
const mongo = require('mongodb');
const baseDir = process.cwd();
const properties = JSON.parse(fs.readFileSync(path.join(baseDir, 'properties.json')));
const assert = require('assert');
const http = require('http');
logger.info('properties', properties);
logger.info('connecting to db', properties.mongoConnectUrl);
mongo.MongoClient.connect(properties.mongoConnectUrl, { useNewUrlParser: true }, function (err, client) {
assert.equal(null, err);
logger.info('Connected successfully to mongodb server');
// creating indexes
const db = client.db(properties.dbName);
db.collection('mailboxes').createIndex( {'name': 1}, { unique: true } );
db.collection('tokens').createIndex( {'ip': 1}, { unique: true } );
const serverApp = require('./server/app/serverapp')(properties, db);
/**
* Create HTTP server.
*/
const server = http.createServer(serverApp);
const port = process.env.PORT || properties.appListenPort || '3000';
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port, function () {
logger.info('API server listening');
});
const smtp = require('./server/app/smtp')(properties, db);
});