-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlearnfy.js
63 lines (48 loc) · 1.5 KB
/
learnfy.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
61
62
63
/**
*
*/
// Require .env to parse enviroment variables
require('dotenv').load();
/**
* --- Node modules and useful variables
*/
var express = require('express');
var bodyParser = require('body-parser');
var morgan = require('morgan');
var path = require('path');
var cookieParser = require('cookie-parser');
var config = require('./config/config');
var app = express();
var public_folder = 'public';
/**
* -- Setting the app
*/
// use body parser so we can grab information from POST requests
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// configure our app to handle CORS requests
app.use(function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type, Authorization');
next();
});
// log all requests to the console
//app.use(morgan('dev'));
// Setting port and static path to express
app.use(express.static(path.join(__dirname, public_folder)));
/**
* -- Configuring Routes
*/
var apiRoutes = require('./app/routes/api')(app, express);
app.use('/api', apiRoutes);
// Send users to front-end
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname + '/' + public_folder + '/index.html'));
});
/**
* Set the application to listen
*/
app.listen(config.port);
console.log("- Express server listening on port " + config.port);