-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
36 lines (32 loc) · 1.07 KB
/
index.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
/*
* S3rver on Deta Micro w/ Deta Base (metadata) + Drive (files) storage
*
* ENV BUCKETS = comma separated buckets (test,default,etc)
* ENV DETA_TOKEN = provided by Micro runtime
* ENV DETA_RUNTIME = provided by Micro runtime
*
*/
const express = require('express')
const app = express()
const cors = require('cors');
const S3rver = require('@qxip/s3rver');
// Set Buckets from BUCKETS ENV csv
var BUCKETS = process.env.BUCKETS.split(',').map(name => ({name})) || false;
const s3rver = new S3rver({
port: 4569,
address: 'localhost',
silent: false,
directory: '/tmp/s3',
allowMismatchedSignatures: true,
vhostBuckets: false,
configureBuckets: BUCKETS || [{ name: 'test'}]
}).run(function(){ console.log('s3rver running')});
// CORS middleware
app.use(cors());
// S3 API middleware
app.all('*', (req, res) => {
s3rver.getMiddleware()(req, res);
})
const isMicro = process.env.DETA_RUNTIME || process.env.DETA_RUNTIME || false;
if (!isMicro) app.listen({port: process.env.PORT || 4568, host: process.env.HOST || "0.0.0.0"})
module.exports = app;