niViz

niViz Git Source Tree

Root/server.js

1/*
2 * niViz -- snow profiles visualization
3 * Copyright (C) 2015 WSL/SLF - Fluelastrasse 11 - 7260 Davos Dorf - Switzerland.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/*eslint strict: [2, "global"] */
20'use strict';
21
22var join = require('path').join;
23var debug = require('debug')('niviz:server');
24
25var PORT = process.env.PORT || 8000;
26
27var express = require('express');
28var app = express();
29
30var Mincer = require('mincer');
31var assets = require('./assets')();
32
33app
34 .set('views', join(__dirname, 'ui'))
35 .set('view engine', 'pug')
36
37 .engine('html', require('ejs').renderFile)
38
39 .use(assets.options.serve, Mincer.createServer(assets.env))
40
41 .use(express.static(join(__dirname, '../public')))
42
43 .use('/resources', express.static('test/fixtures'))
44
45 .use('/img', express.static('assets/img'))
46
47 .get('/simple.html', function (req, res) {
48 res.render('simple.pug', { development: true } );
49 })
50
51 .get('*', function (req, res) {
52 res.render('index.pug', { development: true } );
53 })
54
55 .use(function (req, res) {
56 debug('%s not found', req.url);
57
58 res
59 .status(404)
60 .type('txt')
61 .send('not found');
62 })
63
64 .listen(PORT, function () {
65 debug('listening on port %d', PORT);
66 });

Archive Download this file

Branches