-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
34 lines (26 loc) · 957 Bytes
/
index.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
const express = require('express');
const app = express();
const formidableMiddleware = require('express-formidable');
const mongoose = require('mongoose');
// Load in environment variables
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}
// Import routes
const apiRoutes = require('./api-routes');
// Configure bodyparser to handle post requests
app.use(formidableMiddleware());
// Use mongo env URL or localhost for testing
const mongodbUri = process.env.MONGODB_URI || 'mongodb://localhost/support';
// Connect to Mongoose and set connection variable
mongoose.connect(mongodbUri, {useNewUrlParser: true});
// Create Mongo DB connection
const db = mongoose.connection;
// Setup server port
const port = process.env.PORT;
// Send message for default URL
app.use('/', apiRoutes);
// Launch app to listen to specified port
app.listen(port, function() {
console.log('Running HelpScout Support Form on port ' + port);
});