summaryrefslogtreecommitdiff
path: root/index.ts
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-03-14 01:50:11 +0300
committereug-vs <eug-vs@keemail.me>2021-03-14 01:50:11 +0300
commitdc00c06719b5192518a67177caafe28f5027c16c (patch)
treea05acbbacc75e5c6d7a0ff53f76eba0e28b5f9d5 /index.ts
downloadcommercel-api-dc00c06719b5192518a67177caafe28f5027c16c.tar.gz
feat: create initial feathers app
Diffstat (limited to 'index.ts')
-rw-r--r--index.ts35
1 files changed, 35 insertions, 0 deletions
diff --git a/index.ts b/index.ts
new file mode 100644
index 0000000..a7411fd
--- /dev/null
+++ b/index.ts
@@ -0,0 +1,35 @@
+import mongoose from 'mongoose';
+import Promise from 'bluebird';
+import app from './app';
+
+mongoose.Promise = Promise;
+
+
+const PORT = process.env.PORT || 3030;
+const MONGODB_URL = process.env.MONGODB_URI || 'mongodb://localhost:27017/commercel';
+const { MONGODB_USER, MONGODB_PASSWORD } = process.env;
+
+mongoose.connect(MONGODB_URL, {
+ user: MONGODB_USER,
+ pass: MONGODB_PASSWORD,
+ useNewUrlParser: true,
+ useUnifiedTopology: true,
+ useCreateIndex: true,
+ useFindAndModify: false,
+ family: 4 // Use IPv4, skip trying IPv6
+});
+
+const db = mongoose.connection;
+db.on('error', console.error.bind(console, 'connection error:'));
+db.once('open', () => {
+ console.log('Connection to MongoDB successful');
+});
+
+// Add any new real-time connection to the `everybody` channel
+app.on('connection', connection => app.channel('everybody').join(connection));
+// Publish all events to the `everybody` channel
+app.publish(() => app.channel('everybody'));
+
+
+app.listen(PORT).on('listening', () => console.log(`Feathers server listening on localhost:${PORT}`));
+