Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.use(loopback.bodyParser());
app.use(loopback.methodOverride());
/*
* 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)
try {
var explorer = require('loopback-explorer')(app);
app.use('/explorer', explorer);
app.once('started', function(baseUrl) {
console.log('Browse your REST API at %s%s', baseUrl, explorer.route);
});
} catch(e){
console.log(
'Run `npm install loopback-explorer` to enable the LoopBack explorer'
);
}
/*
* EXTENSION POINT
app.use(loopback.bodyParser());
app.use(loopback.methodOverride());
/*
* 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)
try {
var explorer = require('loopback-explorer')(app);
app.use('/explorer', explorer);
app.once('started', function(baseUrl) {
console.log('Browse your REST API at %s%s', baseUrl, explorer.route);
});
} catch(e){
console.log(
'Run `npm install loopback-explorer` to enable the LoopBack explorer'
);
}
/*
* EXTENSION POINT
loopback.remoteMethod(
WeatherService.weather, {
accepts: [
{arg: 'zip', type: 'string', required: true,
http: {source: 'query'}}
],
returns: {arg: 'result', type: 'object', root: true},
http: {verb: 'get', path: '/weather'}
}
);
// Expose to REST
app.model(WeatherService);
// LoopBack REST interface
app.use(app.get('restApiRoot'), loopback.rest());
// API explorer (if present)
try {
var explorer = require('loopback-explorer')(app);
app.use('/explorer', explorer);
app.once('started', function (baseUrl) {
console.log('Browse your REST API at %s%s', baseUrl, explorer.route);
});
} catch (e) {
console.log(
'Run `npm install loopback-explorer` to enable the LoopBack explorer'
);
}
app.use(loopback.urlNotFound());
app.use(loopback.errorHandler());
// dependencies
var loopback = require('loopback');
var boot = require('loopback-boot');
// server
var server = module.exports = loopback();
boot(server, __dirname);
// middleware
server.use(loopback.rest());
// 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};
if(token) {
newLoopbackJsonSchemaApp: function(config) {
var app = loopback();
app.set('restApiRoot', '/api');
loopbackJsonSchema.init(app, config || {});
loopbackJsonSchema.enableJsonSchemaMiddleware(app);
app.use(app.get('restApiRoot'), loopback.rest());
app.use(loopback.errorHandler());
return app;
}
};
it('maps the URL to a namespaced URL', function(done) {
var observedUrl;
app.use(function(req, res, next) {
observedUrl = req.url;
next();
});
app.use(app.get('restApiRoot'), loopback.rest());
request(app).get('/api/1/Joe/Todos').end(function(err, res) {
if (err) return done(err);
expect(observedUrl).to.equal('/api/1_Joe_Todos');
done();
});
});
app.model(Post)
app.model(Author)
app.model(Comment)
app.model(Parent)
app.model(Critic)
app.model(Empty)
Comment.belongsTo(Post)
Post.hasMany(Comment)
Post.belongsTo(Author)
Post.belongsTo('parent', {polymorphic: true})
Post.hasAndBelongsToMany(Critic)
Author.hasMany(Post)
Author.hasMany(Comment, {through: Post})
app.use(loopback.rest())
})
const ds = loopback.createDataSource('memory')
const Post = ds.createModel('post', {title: String})
const Comment = ds.createModel('comment', {title: String})
const Author = ds.createModel('author', {name: String})
app.model(Post)
app.model(Author)
app.model(Comment)
Post.hasMany(Comment)
Post.belongsTo(Author)
Comment.belongsTo(Author)
app.use(loopback.rest())
})
function createRestAppAndListen() {
const app = loopback({localRegistry: true});
app.set('host', '127.0.0.1');
app.set('port', 0);
app.set('legacyExplorer', false);
app.set('remoting', {
errorHandler: {debug: true, log: false},
context: false,
});
app.use(loopback.rest());
app.locals.handler = app.listen();
return app;
}