loopback-component-storage/example/app.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-01-24 17:32:48 +00:00
var loopback = require('loopback')
2014-01-24 17:44:58 +00:00
, app = module.exports = loopback();
2013-06-25 16:29:53 +00:00
2014-01-24 17:32:48 +00:00
var path = require('path');
2013-06-25 16:29:53 +00:00
2014-01-24 17:32:48 +00:00
app.use(app.router);
2013-06-25 16:29:53 +00:00
2014-01-24 17:32:48 +00:00
// expose a rest api
app.use('/api', loopback.rest());
app.use(loopback.static(path.join(__dirname, 'public')));
2013-06-25 16:29:53 +00:00
2014-01-24 17:32:48 +00:00
app.configure(function () {
2014-01-24 17:44:58 +00:00
app.set('port', process.env.PORT || 3000);
2013-06-25 16:29:53 +00:00
});
2013-06-25 20:06:54 +00:00
2014-01-24 17:32:48 +00:00
var ds = loopback.createDataSource({
2014-01-24 17:44:58 +00:00
connector: require('../index'),
provider: 'filesystem',
root: path.join(__dirname, 'storage')
2013-06-25 20:06:54 +00:00
});
2014-01-24 17:32:48 +00:00
var container = ds.createModel('container');
app.model(container);
2014-03-22 00:30:30 +00:00
/*
2014-01-24 17:32:48 +00:00
app.get('/', function (req, res, next) {
2014-01-24 17:44:58 +00:00
res.setHeader('Content-Type', 'text/html');
var form = "<html><body><h1>Storage Service Demo</h1>" +
"<a href='/api/containers'>List all containers</a><p>" +
2014-01-24 17:44:58 +00:00
"Upload to container c1: <p>" +
"<form method='POST' enctype='multipart/form-data' action='/containers/container1/upload'>"
+ "File to upload: <input type=file name=uploadedFiles multiple=true><br>"
+ "Notes about the file: <input type=text name=note><br>"
+ "<input type=submit value=Upload></form>" +
"</body></html>";
res.send(form);
res.end();
2013-06-25 20:06:54 +00:00
});
2014-03-22 00:30:30 +00:00
*/
2014-01-24 17:32:48 +00:00
app.listen(app.get('port'));
console.log('http://127.0.0.1:' + app.get('port'));