loopback-component-storage/example/app.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

2014-01-24 17:32:48 +00:00
var loopback = require('loopback')
, 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(loopback.rest());
2013-06-25 16:29:53 +00:00
2014-01-24 17:32:48 +00:00
app.configure(function () {
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({
connector: require('../index'),
2013-06-25 20:06:54 +00:00
provider: 'filesystem',
root: path.join(__dirname, 'storage')
});
2014-01-24 17:32:48 +00:00
var container = ds.createModel('container');
app.model(container);
app.get('/', function (req, res, next) {
res.setHeader('Content-Type', 'text/html');
var form = "<html><body><h1>Storage Service Demo</h1>" +
"<a href='/containers'>List all containers</a><p>" +
"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-01-24 17:32:48 +00:00
app.listen(app.get('port'));
console.log('http://127.0.0.1:' + app.get('port'));