-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
52 lines (41 loc) · 1.59 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
var express = require('express');
var path = require('path');
var firebaseApi = require('./server/firebaseApi');
var app = express();
var publicPath = path.resolve(__dirname, 'public');
app.use(express.static(publicPath));
// views is directory for all template files
var viewsPath = path.resolve(__dirname, 'views');
app.set('views', viewsPath);
app.set('view engine', 'ejs');
var renderWithPreview = function(notebookId, pictureId, response) {
response.render('pages/index', {
pngUrl: 'http://www.dashdrawer.com/png/' + notebookId + '/' + pictureId
});
};
app.get('/', function(request, response) {
renderWithPreview('default', 'bars', response);
});
app.get('/notebook/:notebookId/picture/:pictureId/*', function(request, response) {
var notebookId = request.params.notebookId;
var pictureId = request.params.pictureId;
renderWithPreview(notebookId, pictureId, response);
});
app.get('/png/:notebookId/:pictureId', function(request, response) {
var notebookId = request.params.notebookId;
var pictureId = request.params.pictureId;
firebaseApi.getPngUri(notebookId, pictureId, function(pngUri) {
response.render('pages/png', {
pngUri: pngUri
});
});
});
app.get('/fonts/*', function(request, response) {
// TODO - I don't have enough control of the build system to get it to go where I want
var fontPath = path.join(publicPath, 'build', request.originalUrl);
console.log('sending file', fontPath);
response.sendFile(fontPath);
});
var serverType = process.env.NODE_ENV === 'production' ? 'pro' : 'dev';
var server = require('./server/' + serverType + '.js');
server(app);