Skip to content

Instantly share code, notes, and snippets.

@victorpavlenko
Created July 15, 2016 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorpavlenko/34646435b2d9705a60daaea6ed9108a0 to your computer and use it in GitHub Desktop.
Save victorpavlenko/34646435b2d9705a60daaea6ed9108a0 to your computer and use it in GitHub Desktop.
import {
express,
aws,
multer,
multerS3,
body
} from './modules';
import {
login,
signin
// handleReset,
// forgot
} from '../auth';
let api = express.Router();
aws.config.loadFromPath('./s3.json');
// api.post('/reset', handleReset(), (req, res, next) => {
// next();
// });
// api.post('/forgot', forgot(), (req, res, next) => {
// next();
// });
api.post('/login', login(), (req, res, next) => {
next();
});
api.post('/signin', body, signin());
let upload = multer({
limits: {
files: 1,
fileSize: 10000000 // 10MB
},
storage: multerS3({
s3: new aws.S3(),
acl: 'public-read',
bucket: 'lifographprofilepictures',
key: function (req, file, cb) {
cb(null, file.originalname);
}
})
}).any();
api.post('/upload', (req, res) => {
if (!req.user) {
upload(req, res, (err) => {
if (err) {
console.log('app.post(\'/upload\': err: ', err);
res.status(500).send({ error: 'upload failure' });
return;
}
let result = req.files.length ? req.files.shift() : req.files;
res.status(201).send({result: result});
});
} else {
res.status(401).send({ error: 'not authorized' });
}
});
export const apiRoute = api;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment