-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
61 lines (50 loc) · 1.47 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
var http = require('http');
var express = require('express');
var path = require('path');
var _ = require("underscore");
var path = require("path");
var sass = require('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());
const dotenv = require('dotenv');
dotenv.config();
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);
};
app.get('/lens.css', function(req, res) {
var result = sass.compile("lens.scss");
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+"/");
});