-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
64 lines (50 loc) · 1.61 KB
/
app.js
File metadata and controls
64 lines (50 loc) · 1.61 KB
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
64
const responseFactory = require("./src/util/ResponseFactory");
const config = require('./src/config/config');
const mongoose = require('mongoose');
const HTTPServer = require("./src/util/HTTPServer.js");
const gulp = require('gulp');
const uglify = require('gulp-uglify');
const babel = require('gulp-babel');
const del = require('del');
let paths = {
scripts: {
built: "src/public/js/build",
src: "src/client/js/*.js"
}
}
var app = {};
// Configuration
app.config = config;
app.responseFactory = responseFactory;
// Check if user is signed in
app.loggedInMiddleware = (req, res, next) => {
if (!req.user) return res.status(403).redirect('/signin');
next();
}
// Make a new instance of our http server
app.httpServer = new HTTPServer(app);
app.server = require('http').createServer(app.httpServer.server);
// Connect to the database
mongoose.connect(config.database);
gulp.task('clean', function() {
return del(['/src/public/js/build']);
});
// Process JS for niceity of web browsers
gulp.task('scripts', ['clean'], (cb) => {
console.log("Processing JavaScript...");
let t = gulp.src(paths.scripts.src)
t = t.pipe(babel({
presets: ['es2015']
}))
if(!config.debug) t = t.pipe(uglify());
t.pipe(gulp.dest(paths.scripts.built));
console.log("Finished Processing JavaScript");
return t;
});
// Rerun the task when a file changes
gulp.task('watch', () => {
gulp.watch(paths.scripts.src, ['scripts']);
});
gulp.task('default', ['watch', 'scripts']);
gulp.start(['watch', 'scripts'])
app.server.listen(config.port, config.onlyListenLocal ? "127.0.0.1" : null);