This repository has been archived by the owner on Mar 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
72 lines (59 loc) · 1.74 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
68
69
70
71
72
var http = require('http');
var express = require('express');
var path = require('path');
var _ = require("underscore");
var fs = require('fs');
var path = require("path");
var sass = require('node-sass');
var browserify = require('browserify');
var app = express();
var port = process.env.PORT || 4001;
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.get('/lens.js', function (req, res, next) {
browserify({ debug: true, cache: false })
.add(path.join(__dirname, "boot.js"))
.bundle()
.on('error', function(err, data){
console.error(err.message);
res.send('console.log("'+err.message+'");');
})
.pipe(res);
});
var handleError = function(err, res) {
console.error(err);
res.status(400).json(err);
};
var renderSass = function(cb) {
sass.render({
file: path.join(__dirname, "lens.scss"),
sourceMap: true,
outFile: 'lens.css',
}, cb);
};
app.get('/lens.css', function(req, res) {
renderSass(function(err, result) {
if (err) return handleError(err, res);
res.set('Content-Type', 'text/css');
res.send(result.css);
});
});
app.get('/lens.css.map', function(req, res) {
renderSass(function(err, result) {
if (err) return handleError(err, res);
res.set('Content-Type', 'text/css');
res.send(result.map);
});
});
// Serve files from root dir
app.use(express.static(__dirname));
app.use(express.static(path.join(__dirname, 'assets')));
// Serve Lens in dev mode
// --------
app.use(app.router);
http.createServer(app).listen(port, function() {
console.log("Lens running on port " + port);
console.log("http://127.0.0.1:"+port+"/");
console.log("To open a local example file goto http://127.0.0.1:"+port+"?url=PATH_TO_FILE");
});