-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathserver.js
More file actions
40 lines (32 loc) · 1.3 KB
/
server.js
File metadata and controls
40 lines (32 loc) · 1.3 KB
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
const express = require('express');
const sassMiddleware = require('node-sass-middleware');
const path = require('path');
const chalk = require('chalk');
const livereload = require('livereload');
const Exercise = require('./exercise');
module.exports = function (opts) {
var server = livereload.createServer({
exts: ['scss', 'html']
});
let pth = path.join(__dirname, '..', 'exercises', opts.exercise, '**/*');
server.watch(pth);
let app = express();
let sassMw = sassMiddleware({
/* Options */
src: path.join(__dirname, '..', 'exercises', opts.exercise, 'src', 'sass'),
dest: path.join(__dirname, '..', 'exercises', opts.exercise, 'public'),
outputStyle: 'expanded'
});
// Note: you must place sass-middleware *before* `express.static` or else it will
// not work.
let publicPath = path.join(__dirname, '..', 'exercises', opts.exercise, 'public');
let staticMw = express.static(publicPath);
app.use(sassMw);
app.use('/', staticMw);
app.use('/js', express.static(path.join(__dirname, '..', 'public', 'js')));
app.use('/css', express.static(path.join(__dirname, '..', 'public', 'css')));
new Exercise(opts.exercise).load().begin();
app.listen(opts.port);
console.log(chalk.yellow('Running on http://localhost:' + opts.port + '. Press Ctrl + c to stop'));
return app;
}