-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (31 loc) · 1.2 KB
/
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
35
36
37
38
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
// get environment (dev or prod) based on environment variable
const env = process.env.ENV || 'prod';
console.log('environment:', env);
const configuration = env === 'devhosted' ? 'prod' : env;
console.log('configuration:', configuration);
const account = env === 'devhosted' ? 'dev' : env;
console.log('account:', account);
// set the environment in the environment service
const environment = require('./src/environment');
environment.setEnv(account);
environment.setDevMode(configuration === environment.dev);
// create a new express app
const app = express();
// Enable CORS
app.use(cors());
// Enable the use of request body parsing middleware
app.use(bodyParser.json({ limit: '10mb' }));
app.use(bodyParser.urlencoded({
extended: true
}));
// create route handlers for the provider
const provider = require('./src/provider');
provider.createHandlers(app);
// Launch the API Server at PORT, or default port 8080 (8081 for dev config)
const port = process.env.PORT || (configuration === 'prod' ? 8080 : 8081);
app.listen(port, () => {
console.log('SnapMaster HTTP POST provider listening on port', port);
});