-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
61 lines (52 loc) · 1.92 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const express = require('express');
const path = require('path');
const favicon = require('serve-favicon');
const logger = require('morgan');
const exphbs = require('express-handlebars');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const multer = require('multer');
require('dotenv').config();
// setup
const index = require('./routes/index');
const bucketList = require('./routes/bucketList');
const bucketPage = require('./routes/bucketPage');
const upload = require('./routes/upload');
const download = require('./routes/download');
const deleteFile = require('./routes/deleteFile');
const createBucket = require('./routes/createBucket');
const deleteBucket = require('./routes/deleteBucket');
const app = express();
// setup storj environment
const { Environment } = require('storj');
const storj = new Environment({
bridgeUrl: process.env.BRIDGE_URL,
bridgeUser: process.env.BRIDGE_EMAIL,
bridgePass: process.env.BRIDGE_PASS,
encryptionKey: process.env.ENCRYPT_KEY,
logLevel: 4
});
// view engine setup
app.engine('.hbs', exphbs({defaultLayout: 'layout', extname: '.hbs'}));
app.set('view engine', '.hbs');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
// passes storj in middleware
app.use((req, res, next) => {
req.storj = storj;
next();
});
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use('/', index);
app.get('/bucketList', bucketList);
app.get('/bucketList/:bucketId', bucketPage);
app.post('/bucketList/:bucketId', upload);
app.get('/bucketList/:bucketId/:fileId', download);
app.get('/bucketList/:bucketId/:fileId/deleteFile', deleteFile);
app.get('/bucketList/:bucketId/deleteBucket', deleteBucket);
app.get('/createBucket', createBucket);
app.use(express.static(path.join(__dirname, 'public')));
module.exports = app;