module.exports = function() { var lmv = new Lmv(config) lmv.initialize() var router = express.Router() /////////////////////////////////////////////////////////////////////////// // 2-legged token // /////////////////////////////////////////////////////////////////////////// router.get('/2legged', async (req, res) => { try { var response = await lmv.getToken() return json(response) } catch (error) { res.status(error.statusCode || 404); res.json(error); } }) /////////////////////////////////////////////////////////////////////////// // 3-legged token // /////////////////////////////////////////////////////////////////////////// router.get('/3legged', async (req, res) => { try { var authSvc = ServiceManager.getService( 'AuthSvc'); var token = await authSvc.getToken(req) res.json(token) } catch (error) { res.status(error.statusCode || 404); res.json(error); } }) return router; }
.on ('end', function () { console.log ('-> upload done') ; if ( fileName == '' ) { res.status(500).end('No file submitted!'); } // Now upload it to OSS var bucketCreationData = { bucketKey: bucketName, servicesAllowed: {}, policyKey: 'transient' }; // Getting a new key lmv.initialize().then( // initialize success function() { // Getting the bucket lmv.getBucket(bucketName, true, bucketCreationData).then( // getBucket success function() { // Uploading the file var tmpFileName = path.join(form.uploadDir, fileName); lmv.upload( tmpFileName, bucketName, fileName).then( // upload success function(uploadInfo){ // Send back the data res.json(uploadInfo); }, // upload error function(err) { res.status(500).end('Could not upload file into bucket!'); } ); }, // getBucket error function(err) { res.status(500).end('Could not create bucket for file!'); } ); }, // initialize error function (err) { res.status(500).end('Could not get access token!'); } ); });
var favicon = require('serve-favicon'); var Lmv = require('view-and-data'); var express = require('express'); var app = express(); app.use('/', express.static(__dirname + '/www/')); app.use(favicon(__dirname + '/www/img/favicon.ico')); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); app.use(cookieParser()); var lmv = new Lmv(lmvConfig); //async init of our token API lmv.initialize().then( function() { app.use('/api/token', require('./routes/api/token')(lmv)); }, function(error) { console.log(error); }); app.set('port', process.env.PORT || 3000); var server = app.listen(app.get('port'), function() { console.log('Server listening on: ');