-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
60 lines (49 loc) · 1.39 KB
/
server.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import 'idempotent-babel-polyfill';
// import 'intersection-observer';
import BitScoop from 'bitscoop-sdk';
import config from 'config';
import express from 'express';
import mongodb from 'mongodb';
import { Nuxt, Builder } from 'nuxt';
import nuxtConfig from './nuxt.config.js';
const BITSCOOP_API_KEY = config.bitscoop.api_key;
const MONGODB_URI = config.mongodb.address;
const ICE_SERVERS = config.iceServers;
const LISTEN_PORT = config.listenPort;
const opts = {
poolSize: 5
};
const bitscoop = new BitScoop(BITSCOOP_API_KEY, config.bitscoop.arguments);
const app = express();
const nuxt = new Nuxt(nuxtConfig);
const builder = new Builder(nuxt);
Promise.resolve()
.then(async function() {
let mongo = await new Promise(function(resolve, reject) {
mongodb.MongoClient.connect(MONGODB_URI, opts, function(err, db) {
if (err) {
reject(err);
}
else {
resolve(db);
}
});
});
global.env = {
databases: {
mongo: mongo
},
bitscoop: bitscoop,
iceServers: ICE_SERVERS
};
// CORS
app.use(function(req, res, next) {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
builder.build();
app.use(nuxt.render);
app.listen(LISTEN_PORT, '0.0.0.0');
console.log('Nuxt App listening on: ' + LISTEN_PORT); //eslint-disable-line no-console
});