basic static sample server

This commit is contained in:
Felix Roos
2022-07-01 10:45:25 +02:00
parent 8a1cd32d50
commit e44313f631
4 changed files with 874 additions and 3636 deletions
+1
View File
@@ -10,6 +10,7 @@
"snapshot": "cd repl && npm run snapshot",
"repl": "cd repl && npm run dev",
"osc": "cd packages/osc && npm run server",
"sampler": "cd ./repl/public/samples && node ../../packages/webaudio/sample-server.js",
"build": "rm -rf out && cd repl && npm run build && cd ../tutorial && npm run build",
"preview": "npx serve ./out",
"deploy": "gh-pages -d out",
+834 -3636
View File
File diff suppressed because it is too large Load Diff
+5
View File
@@ -29,5 +29,10 @@
"homepage": "https://github.com/tidalcycles/strudel#readme",
"dependencies": {
"@strudel.cycles/core": "^0.1.2"
},
"devDependencies": {
"koa": "^2.13.4",
"koa-static": "^5.0.0",
"@koa/cors": "^3.3.0"
}
}
+34
View File
@@ -0,0 +1,34 @@
// "sampler": "cd ./repl/public/samples && node ../../../packages/webaudio/sample-server.js",
// "sampler": "http-server ./repl/public",
import fs from 'fs';
import path from 'path';
import Koa from 'koa'; // CJS: require('koa');
import cors from '@koa/cors';
import serve from 'koa-static'; // CJS: require('koa-static')
const cwd = process.cwd();
const yellow = '\x1b[33m%s\x1b[0m';
// get array of all folders in cwd:
const banks = fs.readdirSync(cwd).filter((f) => fs.statSync(path.join(cwd, f)).isDirectory());
const app = new Koa();
app.use(cors());
app.use(serve(cwd));
app.use((ctx, next) => {
return next().then(() => {
if (ctx.path === '/') {
ctx.body = 'banks: ' + banks.join(', ');
}
});
});
const port = 1234;
app.listen(port);
console.log(yellow, `strudel sampler running at http://localhost:${port}`);
// node: get current working directory
console.log(yellow, 'cwd: ' + cwd);
console.log('found banks:');
banks.map((c) => console.log(yellow, c));