Suno-style web UI for a self-hosted MiniMax-Music3 inference server
TypeScript ai-musicdiffusersdockerexpressminimaxminimax-musicmusic-generationreactself-hostedsgl-omnisunotailwindcsstext-to-musictypescriptvite
test: path-prefixed upstream base URLs; document /upstream/music3 form
Adam Benhassen37b5f2060959
diff --git a/README.md b/README.mdindex e0463e2..b0592fe 100644--- a/README.md+++ b/README.md@@ -56,7 +56,7 @@ git clone https://github.com/adambenhassen/minimax-music-ui.gitcd minimax-music-uinpm installnpm run build-MUSIC_API=http://<inference-host>:7862 npm start+MUSIC_API=http://<inference-host>:8080/upstream/music3 npm start# → http://localhost:8787```@@ -71,7 +71,7 @@ docker build -t minimax-music-ui .docker run -d -p 8787:8787 -v "$PWD/data:/data" minimax-music-ui```-Set `MUSIC_API` / `MUSIC_API_KEY` in the environment (or a `.env` next to `docker-compose.yml`) to pin the inference server; leave them unset to configure it from the Settings page. When the inference server runs on the Docker host, use `http://host.docker.internal:7862`.+Set `MUSIC_API` / `MUSIC_API_KEY` in the environment (or a `.env` next to `docker-compose.yml`) to pin the inference server; leave them unset to configure it from the Settings page. When the inference server runs on the Docker host, use `http://host.docker.internal:<port>/…`.### Configuration@@ -83,7 +83,7 @@ The inference server address is resolved in this order:| Variable | Default | Description ||---|---|---|-| `MUSIC_API` | – | Base URL of the inference server (overrides Settings) |+| `MUSIC_API` | – | Base URL of the inference server, path prefix allowed, e.g. `http://host:8080/upstream/music3` (overrides Settings) || `MUSIC_API_KEY` | – | Sent as `Authorization: Bearer …` if the inference server was started with `--api-key` (overrides Settings) || `PORT` | `8787` | Port for the UI server || `DATA_DIR` | `./data` | Where `library.json`, `templates.json`, `settings.json` and `tracks/` live |@@ -122,7 +122,7 @@ FAKE_AUDIO=/path/to/real.wav FAKE_ADVANCE_MS=1500 npm run fake -w server## Upstream API-The server expects the inference box to speak this contract:+The server expects the inference box to speak this contract, relative to `MUSIC_API` (which may include a path prefix such as `/upstream/music3`):| Method | Path | ||---|---|---|diff --git a/server/src/settings.ts b/server/src/settings.tsindex df10dff..e46a081 100644--- a/server/src/settings.ts+++ b/server/src/settings.ts@@ -28,7 +28,7 @@ export function normalizeMusicApi(v: unknown): string {try {url = new URL(v.trim());} catch {- throw new ValidationError('musicApi must be a valid URL, e.g. http://100.105.185.107:7862');+ throw new ValidationError('musicApi must be a valid URL, e.g. http://100.105.185.107:8080/upstream/music3');}if (url.protocol !== 'http:' && url.protocol !== 'https:') throw new ValidationError('musicApi must be http or https');return url.toString().replace(/\/+$/, '');diff --git a/server/test/app.test.ts b/server/test/app.test.tsindex 25555d1..c070bc4 100644--- a/server/test/app.test.ts+++ b/server/test/app.test.ts@@ -149,6 +149,25 @@ describe('app', () => {expect(again.effective()).toMatchObject({ musicApi: fake!.url, apiKey: null });});+ it('works with a path-prefixed upstream base URL', async () => {+ const { app, poller } = await setup({ prefix: '/upstream/music3' });+ expect(fake!.url).toMatch(/\/upstream\/music3$/);+ expect((await request(app).get('/api/health')).body.upstreamReachable).toBe(true);+ const { body } = await request(app).post('/api/generate').send({ prompt: 'x', format: 'flac' });+ for (let i = 0; i < 8; i++) await poller.tick();+ expect((await request(app).get('/api/library')).body[0]).toMatchObject({ id: body[0].id, status: 'done' });+ expect(fake!.requests.map((r) => r.path)).toEqual(expect.arrayContaining(['/health', '/generate', `/jobs/${body[0].jobId}`, `/jobs/${body[0].jobId}/audio`]));+ });++ it('settings keep a path prefix and drop trailing slashes', async () => {+ const { app } = await setup({ prefix: '/upstream/music3' }, null, { musicApi: null, apiKey: null });+ const put = await request(app).put('/api/settings').send({ musicApi: `${fake!.url}/` });+ expect(put.status).toBe(200);+ expect(put.body.musicApi).toBe(fake!.url);+ expect((await request(app).get('/api/health')).body.upstreamReachable).toBe(true);+ expect(fake!.requests.at(-1)?.path).toBe('/health');+ });+it('settings/test probes a candidate URL without saving', async () => {const { app } = await setup({}, null, { musicApi: null, apiKey: null });const ok = await request(app).post('/api/settings/test').send({ musicApi: fake!.url });diff --git a/server/test/fakeUpstream.ts b/server/test/fakeUpstream.tsindex 1cb1d8c..46834b7 100644--- a/server/test/fakeUpstream.ts+++ b/server/test/fakeUpstream.ts@@ -14,6 +14,8 @@ export interface FakeUpstreamOptions {audioBytes?: Buffer;/** milliseconds between auto-advances; 0 = advance on every poll */autoAdvanceMs?: number;+ /** mount the API under a path prefix, e.g. '/upstream/music3' */+ prefix?: string;}export interface FakeUpstream {@@ -43,7 +45,9 @@ export function defaultScript(jobId: string, body: Record<string, unknown>): Ups}export async function startFakeUpstream(opts: FakeUpstreamOptions = {}): Promise<FakeUpstream> {+ const root = express();const app = express();+ root.use(opts.prefix ?? '/', app);app.use(express.json());const requests: FakeUpstream['requests'] = [];const jobs: FakeUpstream['jobs'] = new Map();@@ -98,11 +102,11 @@ export async function startFakeUpstream(opts: FakeUpstreamOptions = {}): Promise});const server: Server = await new Promise((resolve) => {- const s = app.listen(opts.autoAdvanceMs !== undefined && process.env.FAKE_PORT ? Number(process.env.FAKE_PORT) : 0, '127.0.0.1', () => resolve(s));+ const s = root.listen(opts.autoAdvanceMs !== undefined && process.env.FAKE_PORT ? Number(process.env.FAKE_PORT) : 0, '127.0.0.1', () => resolve(s));});const addr = server.address() as { port: number };return {- url: `http://127.0.0.1:${addr.port}`,+ url: `http://127.0.0.1:${addr.port}${opts.prefix ?? ''}`,app,requests,jobs,diff --git a/web/src/components/SettingsPanel.tsx b/web/src/components/SettingsPanel.tsxindex 77558b7..9758c5e 100644--- a/web/src/components/SettingsPanel.tsx+++ b/web/src/components/SettingsPanel.tsx@@ -67,7 +67,7 @@ export function SettingsPanel({ onSaved }: { onSaved: () => void }) {<div><h2 className="text-sm font-semibold">Inference server</h2><p className="text-xs text-zinc-500 mt-1">- Where the MiniMax-Music3 API lives. Values set via <code className="text-zinc-300">MUSIC_API</code> / <code className="text-zinc-300">MUSIC_API_KEY</code> environment variables always win and are shown locked here.+ Base URL of the MiniMax-Music3 API — a path prefix is fine (e.g. <code className="text-zinc-300">http://host:8080/upstream/music3</code>); <code className="text-zinc-300">/generate</code>, <code className="text-zinc-300">/jobs/…</code> and <code className="text-zinc-300">/health</code> are appended. Values set via <code className="text-zinc-300">MUSIC_API</code> / <code className="text-zinc-300">MUSIC_API_KEY</code> environment variables always win and are shown locked here.</p></div>@@ -85,7 +85,7 @@ export function SettingsPanel({ onSaved }: { onSaved: () => void }) {value={musicApi}disabled={settings.locked.musicApi}onChange={(e) => setMusicApi(e.target.value)}- placeholder="http://100.105.185.107:7862"+ placeholder="http://100.105.185.107:8080/upstream/music3"spellCheck={false}/></div>