How to use harp - 10 common examples

To help you get started, we’ve selected a few harp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JonAbrams / synth / synth.js View on Github external
assets.cssPrecompiled()
    );
    var cssPath = '/css/' + cssFilename;
    exports.cssFiles.length = 0;
    exports.cssFiles.push(cssPath);

    /* Make the files available */
    app.use(st({ path: assetsDir, url: '/js', index: false }));
    app.use(st({ path: assetsDir, url: '/css', index: false }));
    console.log('Done');
  } else {
    /* Dev mode */
    app.use( '/js', harp.mount( path.join(process.cwd(), 'front/js') ) );
    app.use( '/css', harp.mount( path.join(process.cwd(), 'front/css') ) );
  }
  app.use( '/html', harp.mount( path.join(process.cwd(), 'front/html') ) );
  app.use( '/bower_components', harp.mount( path.join(process.cwd(), 'front/bower_components') ) );

  /* Render the main index */
  app.set( "views", viewDir );
  app.set('view engine', viewEngine);
  if (!production) app.locals.pretty = true;
  app.get('/', frontend.index);

  /* Provide routes to render the index with preloaded data */
  _(handlers).where({ method: 'get' }).forEach(function (handler) {
    var path = handler.path.replace(/^\/api/, '');
    app.get(path, function (req, res, next) {
      req.handler = handler;
      frontend.index(req, res, next);
    });
  });
github words / ord / index.js View on Github external
var express = require('express')
var harp = require('harp')
var logfmt = require('logfmt')
var merge = require('merge')
var cors = require('cors')
var translate = require('wikipedia-translator')
var wikipedias = require('wikipedias')
var app = module.exports = express()

if (process.env.NODE_ENV !== "test") app.use(logfmt.requestLogger());
app.use(express.static(__dirname + "/public"))
app.use(harp.mount(__dirname + "/public"));
app.set('view engine', 'jade');

app.get('/', cors(), function(req, res) {

  var locals = {
    wikipedias: wikipedias,
    hostname: req.hostname
  }

  // Support the old URL format
  if (req.query.query) {
    var url = require("url").format({
      pathname: "/search",
      query:req.query
    })
    return res.redirect(url)
github mderazon / csu-il / app.js View on Github external
var express = require('express')
var harp = require('harp')
var logger = require('morgan')
var body_parser = require('body-parser')
var mailer = require('./mailer')

var app = express()

var logger_format = ':remote-addr - - [:date] ":method :url" :status ":referrer" ":user-agent"'
app.use(express.static(__dirname + '/_public'))
app.use(logger(logger_format))
app.use(harp.mount(__dirname + '/_public'))

// to get the contact form data
app.use(body_parser.json())
app.use(body_parser.urlencoded({ extended: true }))

app.post('/contact-submit', function (req, res, next) {
  var payload = {
    email: req.body.email,
    name: req.body.name,
    message: req.body.message
  }
  if (!payload.email || !payload.name || !payload.message) {
    return res.send(400, 'One of the fields is missing...')
  }

  mailer(payload, function (err, response) {
github silentrob / harp-editor / server.js View on Github external
app.configure(function () {
    app.use(express.cookieParser('play me off keyboard cat'));
    app.use(express.session({ secret: "keyboard cat", cookie: { maxAge: 1000*60*60*24*365 }}));
    app.use(flash());
    app.use(express.json());
    app.use(express.urlencoded());
    app.use(express.methodOverride());
    app.use(busboy());
    app.use(harp.mount(projectPath));
    app.use(express.static(__dirname + "/public"));
    app.use(dynHelpers.helpers(editor));
    app.set("view engine", "jade");
    app.set('views', __dirname + '/views');
    // Just needed to parse html files
    app.engine('html', require('ejs').renderFile);
  });
github ksoichiro / Android-ObservableScrollView / website / gulpfile.js View on Github external
gulp.task('start', ['copy'], function() {
    // This task is for development locally, so BASE_URL should be empty.
    // $BASE_URL is referenced in harp.json, and it will be replaced by harp (envy).
    process.env.BASE_URL = ''
    harp.server(paths.harp.project, { port: port }, function(err) {
        if (err) {
            gutil.log('Failed to start');
            gutil.log(err);
        } else {
            gulp.watch([paths.docs + '/**/*', '!' + paths.docs + '/**/*.sw*'], ['copyDocs']);
            gulp.watch(paths.bower + '/**/*', ['copyBowerFiles']);
            gutil.log('Started server: http://localhost:' + port);
            gutil.log('Press Ctrl+C to quit');
        }
    });
});
github superhighfives / harp-gulp-browsersync-boilerplate / gulpfile.js View on Github external
gulp.task('serve', function () {
  harp.server(__dirname, {
    port: 9000
  }, function () {
    browserSync({
      proxy: "localhost:9000",
      open: false,
      /* Hide the notification. It gets annoying */
      notify: {
        styles: ['opacity: 0', 'position: absolute']
      }
    });
    /**
     * Watch for scss changes, tell BrowserSync to refresh main.css
     */
    gulp.watch(["*.css", "*.sass", "*.scss", "*.less"], function () {
      reload("main.css", {stream: true});
    });
github ksoichiro / Android-ObservableScrollView / website / gulpfile.js View on Github external
gulp.task('build', ['copy'], function(cb) {
    // This task is for production, so BASE_URL should be a project name.
    // $BASE_URL is referenced in harp.json, and it will be replaced by harp (envy).
    process.env.BASE_URL = '/' + project.name
    harp.compile(paths.harp.project, paths.harp.output, function(err) {
        if (err) {
            gutil.log('build failed: ' + err);
        }
        gutil.log('Compile done');
        cb();
    });
});
github quilljs / quill / scripts / server.js View on Github external
app.use('/quill.js', respond.bind(this, 'main'));
app.use('/test/quill.js', respond.bind(this, 'test'));
app.use('/quill.snow.css', function(req, res, next) {
  res.setHeader('Content-Type', 'text/css');
  fs.readFile('./src/themes/snow/snow.styl', function(err, data) {
    var s = stylus(data.toString());
    s.include('./src/themes/snow');
    s.define('url', stylus.url());
    s.render(function(err, css) {
      res.write(css);
      res.end();
    })
  });
});
app.use(harp.mount(__dirname + '/..'));

app.listen(9000);
console.info('Quill development server listening on port 9000');
github jondashkyle / photo-on-startup / index.js View on Github external
function compileHarp () {
  harp.compile(__dirname + '/' + options.publicPath, '../www', function (err) {
    if (err) throw err;
    events.emit('harp:compiled')
  })
}
github bitvagas / bitvagas / config / express.js View on Github external
app.use(logger('dev'));
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({
        extended: true
    }));
    app.use(cors({ origin: false }));
    app.use(cookieParser());
    app.use(compress());
    app.use(express.static(config.root + '/public'));
    app.use(methodOverride());
    app.use(passport.initialize());
    app.disable('x-powered-by');
    app.use(require('prerender-node').set('prerenderToken', process.env.PRERENDER));

    //Initialize HarpJS
    app.use(harp.mount(config.root + "/public"));

    var api    = glob.sync(config.root + "/app/modules/**/api/*.js");
    var routes = glob.sync(config.root + "/app/modules/**/routes/*.js");
    routes.forEach(function(route){
        require(route)(app);
    });

    api.forEach(function(route){
        //get api name prefix
        app.use('/api', require(route)(app));
    });

    app.get('*', function(request, response) {
        response.render("index", { user : request.user });
    });
};

harp

Static Web Server/Generator/Bundler

MIT
Latest version published 2 years ago

Package Health Score

47 / 100
Full package analysis

Popular harp functions