mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-10 19:07:05 +01:00
Some checks failed
dependency freshness / dependencies on newest stable (push) Has been cancelled
md-naming / markdown naming convention (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint) (push) Has been cancelled
Tests / test (push) Has been cancelled
Tests / web-coverage (push) Has been cancelled
repo-contract / repo contract (push) Has been cancelled
Todo: 9b9342ba
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
// Dev-only Vite plugin that serves the whole web-control API contract from
|
|
// memory (`pnpm dev:mock`). `apply: 'serve'` plus the mode gate in
|
|
// astro.config.mjs keep it out of every production build.
|
|
|
|
import { randomBytes } from 'node:crypto'
|
|
import type { AstroUserConfig } from 'astro'
|
|
import { handle } from './routes.ts'
|
|
|
|
// Vite is Astro's, not a direct dependency: take its Plugin type from there.
|
|
type PluginOption = NonNullable<NonNullable<AstroUserConfig['vite']>['plugins']>[number]
|
|
type Plugin = Extract<PluginOption, { name: string }>
|
|
|
|
export function mockApi(): Plugin {
|
|
// Per-launch token, like the real server's web-<port>.token.
|
|
const token = randomBytes(32).toString('hex')
|
|
return {
|
|
name: 'sbe-mock-api',
|
|
apply: 'serve',
|
|
// src/components/DevToken.astro renders this into every page in dev.
|
|
config() {
|
|
process.env.SBE_DEV_TOKEN = token
|
|
},
|
|
configureServer(server) {
|
|
server.middlewares.use((req, res, next) => {
|
|
handle(req, res, token).then((handled) => {
|
|
if (!handled) next()
|
|
}, next)
|
|
})
|
|
},
|
|
}
|
|
}
|