-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
73 lines (61 loc) · 2.46 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
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
65
66
67
68
69
70
71
72
73
'use strict';
const express = require('express');
const app = express();
const server = require('http').createServer(app);
const cors = require('cors');
const path = require('path');
const Filehound = require('filehound');
const io = require('socket.io')(server);
app.use(cors());
io.on('connection', (client) => {
client.on('event', (data) => {
console.log(data);
});
client.on('disconnect', () => {
console.log('disconnect');
});
});
function loadRoutes(routeDir) {
const routes = Filehound.create()
.path(routeDir)
.ext('js')
.findSync();
routes.forEach((route) => {
app.use('/', require(route));
});
}
function loadNamespaces(namespaceDir) {
const namespaces = Filehound.create()
.path(namespaceDir)
.ext('js')
.findSync();
namespaces.forEach((namespace) => {
const nspListener = require(namespace);
const nsp = io.of(nspListener.name);
nsp.on('connection', nspListener.connection);
});
}
loadRoutes(__dirname + '/routes/');
loadNamespaces(__dirname + '/namespaces/');
app.engine('html', require('hogan-express'));
app.set('view engine', 'html');
app.set('layout', 'layout');
app.set('views', [
path.resolve(process.cwd(), 'views'), // app-secific views
path.resolve(__dirname, 'views') // UI layout and partials
]);
app.use(express.static(path.resolve(process.cwd(), 'public'))); // app-specific static assets
app.use(express.static(path.resolve(__dirname, 'public'))); // UI static assets
app.use('/bootstrap', express.static(path.resolve(process.cwd(), 'node_modules/bootstrap/dist')));
app.use('/bootstrap', express.static(path.resolve(__dirname, 'node_modules/bootstrap/dist')));
app.use('/font-awesome', express.static(path.resolve(process.cwd(), 'node_modules/font-awesome')));
app.use('/font-awesome', express.static(path.resolve(__dirname, 'node_modules/font-awesome')));
app.use('/tether', express.static(path.resolve(process.cwd(), 'node_modules/tether/dist')));
app.use('/tether', express.static(path.resolve(__dirname, 'node_modules/tether/dist')));
app.use('/jquery', express.static(path.resolve(process.cwd(), 'node_modules/jquery/dist')));
app.use('/jquery', express.static(path.resolve(__dirname, 'node_modules/jquery/dist')));
app.use('/cookies-js', express.static(path.resolve(process.cwd(), 'node_modules/cookies-js/dist')));
app.use('/cookies-js', express.static(path.resolve(__dirname, 'node_modules/cookies-js/dist')));
server.listen(8081, () => {
console.log('Collator listening on port 8081!');
});