-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
30 lines (25 loc) · 868 Bytes
/
server.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
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const fs = require('fs');
const port = process.env.PORT || process.env.WEB_PORT || 5000;
const host = process.env.WEB_HOST || '0.0.0.0';
const app = express();
const folder = 'bucket';
app.use(bodyParser.json());
app.use('/', express.static(path.join(__dirname, 'build')));
app.use('/app/*', express.static(path.join(__dirname, 'build')));
app.use('/bucket', express.static(path.join(__dirname, 'bucket')));
app.get('/api/images', (req, res) => {
fs.readdir(folder, (err, items) => {
let resp = items.map(item => {
return {
name: item,
path: '/bucket/' + item
}
});
res.json(resp);
});
});
app.listen(port, host,
() => console.log(`Listening on port ${port}`));