-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
41 lines (34 loc) · 1.11 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
const fs = require('fs');
const path = require('path');
const express = require('express');
const app = express();
express.static.mime.types["wasm"] = "application/wasm";
function allFilesSync(dir, fileList = []) {
fs.readdirSync(dir).forEach(file => {
if (file !== '.DS_Store') {
const filePath = path.join(dir, file);
fileList.push(
fs.statSync(filePath).isDirectory() ? { [file]: allFilesSync(filePath) } : file
);
}
});
return fileList;
}
app.use(express.static('./'));
app.use(express.static('dist'));
app.get('/recorderWorker.js', (request, response) => {
response.header("Access-Control-Allow-Origin", "*");
response.send(`${__dirname}/node_modules/recorderjs/recorderWorker.js`);
});
app.get('/getSamples', (request, response) => {
response.header("Access-Control-Allow-Origin", "*");
const fileslist = allFilesSync(`${__dirname}/static/samples`);
response.send({ fileslist });
});
app.get('*', (req, res) => {
res.sendFile(`${__dirname}/dist/index.html`);
});
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log('app listening on', port);
});