-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
112 lines (97 loc) · 2.84 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
'use strict';
const fs = require('fs');
var app = require('koa')();
var common = require('koa-common');
var router = require('koa-router')();
var hbs = require('koa-hbs');
var find = require('list-files');
var Q = require('q');
var settings = {
viewPathRelative: 'views',
viewPath: __dirname + '/views/',
partialsPath: __dirname + '/views/partials/',
staticPath: __dirname + '/static/',
portfolio: __dirname + '/static/portfolio/'
};
function fileList(directory, mask){
var deferred = Q.defer();
find(function(files) {
deferred.resolve(files);
}, {
dir: directory,
name: mask
});
return deferred.promise;
}
class TemplateDirectory {
constructor(path) {
this.path = path;
return this;
}
readDirectory() {
let files = Q.defer();
fs.readdir(this.path, function(err, filesFound){
files.resolve(filesFound);
});
return files.promise;
}
}
class Views {
static *main(next){
this.status = 200;
yield this.render('main', {title: 'NRG948 Home'});
}
static *populateTemplateName(templateName, next){
this.template = {name: templateName};
yield next
}
static *listTemplates(next) {
this.status = 200;
this.body = yield fileList(settings.viewPathRelative, 'hbs');
}
static *generic(next) {
yield this.render(this.template.name, {title: this.template.name});
this.status = 200;
yield next;
}
static *eventPopulate(event, next) {
this.status = 200;
this.event = event;
yield next;
}
static *portfolio(next) {
var dir = new TemplateDirectory(settings.portfolio);
this.status = 200;
var allfiles = yield dir.readDirectory();
this.body = "param name:" + allfiles;
}
static *portfolioEvent(next) {
var dir = new TemplateDirectory(settings.portfolio);
this.status = 200;
this.event = this.event;
this.body = "param name:" + this.event;
}
static *allredir(next){
this.redirect('https://nrg948.teamapp.com');
}
};
/*router
.param('template', Views.populateTemplateName)
.param('event', Views.eventPopulate)
.get('/', Views.main)
.get('/templates', Views.listTemplates)
.get('/portfolio/:event', Views.portfolioEvent)
.get('/portfolio/', Views.portfolio)
.get('/:template', Views.generic);
*/
router.get('/', Views.allredir);
app
.use(common.responseTime())
.use(common.logger('dev'))
.use(hbs.middleware({ viewPath: settings.viewPath, partialsPath: settings.partialsPath }))
.use(router.routes())
.use(router.allowedMethods())
.use(common.static(settings.staticPath, {defer: true}));
var server = app.listen(80, function () {
console.log('Listening on port %d', server.address().port);
});