This repository has been archived by the owner on Jan 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
67 lines (53 loc) · 1.64 KB
/
server.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
'use strict';
var fs = require('fs'),
async = require('async'),
express = require('express'),
_ = require('underscore');
// Constants
var PORT = 8080;
// App
var app = express();
app.use('/css',express.static('css'));
app.use('/fonts',express.static('fonts'));
app.use('/src',express.static('src'));
app.use('/bower_components',express.static('bower_components'));
app.use('/require.js',express.static('bower_components/requirejs/require.js'));
app.use('/src',express.static('src'));
app.use('/main-built.js',express.static('public/main-built.js'));
function readAsync(file,callback){
}
app.param(['page'], function (req, res, next, pageId) {
var pagesConfig = require('./pages.config.json');
if(pagesConfig[pageId]){
var rootPath = 'src/templates/';
var paths = {
layout:rootPath+'layout.tpl.html',
footer:rootPath+'footer.tpl.html',
main:rootPath+'pages/'+pageId+'.main.tpl.html',
sidebar:rootPath+'pages/'+pageId+'.sidebar.tpl.html'
};
async.map(paths,function(file,callback){
fs.readFile(file, 'utf8', function(err,data){
callback(null,data);
});
},function(err,templates){
_(templates).extend(pagesConfig[pageId]);
var html = _.template(templates.layout)(templates);
res.send(html);
});
}else{
throw 'not a page';
}
});
app.get('/',function(req,res){
res.redirect('/page-foreword');
});
app.get('/page-:page',function(req,res,next){
/*fs.readFile('./src/templates/layout.tpl.html','utf8',function(err,data){
if (err) throw err;
res.send(_.template(data)({title:'Nouvenoau Document'}));
});*/
});
app.use(express.static('public'));
app.listen(PORT);
console.log('Running on http://localhost:' + PORT);