mirror of
https://codeberg.org/uzu/strudel
synced 2026-07-28 07:46:45 -04:00
basic static sample server
This commit is contained in:
@@ -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",
|
||||
|
||||
Generated
+834
-3636
File diff suppressed because it is too large
Load Diff
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
Reference in New Issue
Block a user