software engineering


By Adam K Dean on

One of the many great things about DADI Web is how easy it is to plug in middleware, such as the following SCSS preprocessor (based on node-sass-middleware) which takes any request with prefix, in this case /css, and compiles it's counterpart from the src directory into the dest directory before serving it up.

All you need to do is drop this file into your workspace/middleware directory and make sure the paths are correct.

const sassMiddleware = require('node-sass-middleware')
const path = require('path')
const workdir = process.cwd()

const Middleware = function (app) {
    src: path.join(workdir, 'workspace', 'public', 'scss'),
    dest: path.join(workdir, 'workspace', 'public', 'css'),
    prefix: '/css',
    outputStyle: 'compressed',
    debug: process.env.NODE_ENV === 'development'

module.exports = function (app) {
  return new Middleware(app)

module.exports.Middleware = Middleware

Learn more about DADI Web.