How to use the loopback.static function in loopback

To help you get started, we’ve selected a few loopback 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 rblalock / lb_cms / test_app / app.js View on Github external
app.boot(__dirname);

/*
 * 2. Configure request preprocessing
 *
 *  LoopBack support all express-compatible middleware.
 */

app.use(loopback.favicon());
app.use(loopback.logger(app.get("env") === "development" ? "dev" : "default"));
app.use(loopback.cookieParser(app.get("cookieSecret")));
app.use(loopback.token({model: app.models.accessToken}));
app.use(loopback.json());
app.use(loopback.urlencoded());
app.use(loopback.methodOverride());
app.use(loopback.static(path.join(__dirname, "public")));

/*
 * EXTENSION POINT
 * Add your custom request-preprocessing middleware here.
 * Example:
 *   app.use(loopback.limit('5.5mb'))
 */

/*
 * 3. Setup request handlers.
 */

// LoopBack REST interface
app.use(app.get('restApiRoot'), loopback.rest());

// API explorer (if present)
github coodoo / fullstack-hackathon / Project / ServerApp / server / server.js View on Github external
var loopback = require('loopback');
var boot = require('loopback-boot');
var path = require('path');

var app = module.exports = loopback();

// Bootstrap the application, configure models, datasources and middleware.
// Sub-apps like REST API are mounted via boot scripts.
boot(app, __dirname);

//
app

// static files, for ClientApp
.use( loopback.static(path.resolve(__dirname, '../client')) )

//
.use( '/', function(req, res, next ){
    res.sendFile('ServerApp/client/index.html', {root: '../'});
})

//
app.start = function() {
  // start the web server
  return app.listen(function() {
    app.emit('started');
    console.log('Web server listening at: %s', app.get('url'));
  });
};

// start the server if `$ node server.js`
github malixsys / ionic-loopback-example / server / server.js View on Github external
res.render('linkedAccounts', {user: req.user});
 });
 */

app.get('/auth/logout', function(req, res, next) {
  req.logout();
  res.redirect('/');
  console.log('Logged out', req.user)
});

// -- Mount static files here--
// All static middleware should be registered at the end, as all requests
// passing the static middleware are hitting the file system
// Example:
var path = require('path');
app.use(loopback.static(path.resolve(__dirname, '../client/www')));

// Requests that get this far won't be handled
// by any middleware. Convert them into a 404 error
// that will be handled later down the chain.
app.use(loopback.urlNotFound());

// The ultimate error handler.
app.use(loopback.errorHandler());

app.start = function() {
  // start the web server
  return app.listen(function() {
    app.emit('started');
    console.log('Web server listening at: %s', app.get('url'));

    app.models.user.create({
github freeCodeCamp / freeCodeCamp / server / boot / redirectHttps.js View on Github external
module.exports = function(loopbackApp) {
  var app = express();
  app.set('view engine', 'jade');
  // views in ../views'
  app.set('views', path.join(__dirname, '..'));

  // server static files
  app.use(loopback.static(path.join(
    __dirname,
    '../',
    '../public'
  )));

  // all traffic will be redirected on page load;
  app.use(function(req, res) {
    return res.render('views/redirect-https');
  });

  loopbackApp.once('started', function() {
    app.listen(port, function() {
      console.log('https redirect listening on port %s', port);
    });
  });
};
github strongloop / loopback-example-database / app.js View on Github external
*     } else {
 *       next();
 *     }
 *   });
 */

// Let express routes handle requests that were not handled
// by any of the middleware registered above.
// This way LoopBack REST and API Explorer take precedence over
// express routes.
app.use(app.router);

// The static file server should come after all other routes
// Every request that goes through the static middleware hits
// the file system to check if a file exists.
app.use(loopback.static(path.join(__dirname, 'public')));

// Requests that get this far won't be handled
// by any middleware. Convert them into a 404 error
// that will be handled later down the chain.
app.use(loopback.urlNotFound());

/*
 * 4. Setup error handling strategy
 */

/*
 * EXTENSION POINT
 * Add your custom error reporting middleware here
 * Example:
 *   app.use(function(err, req, resp, next) {
 *     console.log(req.url, ' failed: ', err.stack);
github strongloop / loopback-workspace / server / server.js View on Github external
* EXTENSION POINT
 * Add your custom request-handling middleware here.
 * Example:
 *   app.use(function(req, resp, next) {
 *     if (req.url == '/status') {
 *       // send status response
 *     } else {
 *       next();
 *     }
 *   });
 */

// The static file server should come after all other routes
// Every request that goes through the static middleware hits
// the file system to check if a file exists.
app.use(loopback.static(path.join(__dirname, 'public')));

// Requests that get this far won't be handled
// by any middleware. Convert them into a 404 error
// that will be handled later down the chain.
app.use(loopback.urlNotFound());

/*
 * 4. Setup error handling strategy
 */

/*
 * EXTENSION POINT
 * Add your custom error reporting middleware here
 * Example:
 *   app.use(function(err, req, resp, next) {
 *     console.log(req.url, ' failed: ', err.stack);
github plantinformatics / pretzel / backend / server / server.js View on Github external
//
// - - - - - FILE DELIVERY CONFIG - - - - - -
//
// 

let clientPath = path.resolve(__dirname, '../client')

// default route handling to deliver client files
app.use('/', loopback.static(clientPath));
// using a regex to avoid wildcard matching of api route,
// but delivering files when hitting all other routes.
// this was an issue when providing the confirm token on email
// validation, as the confirm API request would deliver files
// instead of hitting the API as desired.
app.use(/^((?!api).)*$/, loopback.static(clientPath));

module.exports = app; // for testing
github strongloop / loopback-example-offline-sync / app.server.js View on Github external
var User = require('./models/user');
var Todo = require('./models/todo');

// setup the model data sources
User.attachTo(memory);
Todo.attachTo(memory);

// root api path
var apiPath = '/api';

// enable authentication
server.enableAuth();

// middleware
server.use(loopback.static(path.join(__dirname, 'public')));
server.use(loopback.static(path.join(__dirname, 'bower_components', 'angular-route')));
server.use(loopback.token());
server.use(apiPath, loopback.rest());
server.use('/explorer', explorer(server, {basePath: apiPath}));

// locals
server.locals({
  title: 'Todo Example'
});

// view engine
server.engine('html', require('ejs').renderFile);

// home route
server.get('/', function(req, res) {
  var token = req.accessToken;
  var data = {me: undefined};
github cosmojs / universal / server / server.js View on Github external
var bodyParser = require('body-parser');
var boot = require('loopback-boot');
var loopback = require('loopback');
var path = require('path');
var satellizer = require('loopback-satellizer');
var config = require('./config');

var app = module.exports = loopback();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

boot(app, __dirname);

app.use(loopback.static(path.resolve(__dirname, '../client')));

satellizer(app, config);

var indexPath = path.resolve(__dirname, '../client/index.html');
app.get('*', function (req, res) { res.sendFile(indexPath); });

app.start = function() {
  return app.listen(function() {
    app.emit('started');
    console.log('Web server listening at: %s', app.get('url'));
  });
};

if (require.main === module) {
  app.start();
}