cf4cce2225
* Nightly source-language update * add: test embed page for bskyembeds * run prettier * wip * feat: use local dev for bskyembed test.html * feat: commit generated files which i'm not sure about * chore: add basic readme to bskyembed * Revert "feat: commit generated files which i'm not sure about" This reverts commit b891efdaa1fd7ddd4417bfd5267e861a25a93b0e. * chore: revert change to bskyembed/.eslintrc.cjs * chore: remove generated file from bskyweb/static * chore: revert messages.po changes * add dev-snippet command, add dev router * Update README.md * Update bskyembed/test.html * change IS_DEV check to allow localhost --------- Co-authored-by: APiligrim <28320272+APiligrim@users.noreply.github.com> Co-authored-by: Anastasiya Uraleva <anastasiya@Anastasiyas-MacBook-Pro.local> Co-authored-by: Anastasiya Uraleva <anastasiya@Mac.localdomain> Co-authored-by: Elijah Seed-Arita <elijaharita@gmail.com>
59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import fs from 'node:fs'
|
|
import {resolve} from 'node:path'
|
|
|
|
import preact from '@preact/preset-vite'
|
|
import legacy from '@vitejs/plugin-legacy'
|
|
import type {Plugin, UserConfig} from 'vite'
|
|
import paths from 'vite-tsconfig-paths'
|
|
|
|
/**
|
|
* World's hackiest router, for dev only. Serves `/post.html` to requests that start with `/embed/`
|
|
*/
|
|
function devOnlyRouter(): Plugin {
|
|
return {
|
|
name: 'embed-to-post-html',
|
|
configureServer(server) {
|
|
server.middlewares.use((req, res, next) => {
|
|
const url = req.url || ''
|
|
if (!url.startsWith('/embed/')) return next()
|
|
|
|
const html = fs.readFileSync(
|
|
resolve(process.cwd(), 'post.html'),
|
|
'utf8',
|
|
)
|
|
|
|
server
|
|
.transformIndexHtml(url, html)
|
|
.then(transformed => {
|
|
res.statusCode = 200
|
|
res.setHeader('Content-Type', 'text/html')
|
|
res.end(transformed)
|
|
})
|
|
.catch(next)
|
|
})
|
|
},
|
|
}
|
|
}
|
|
|
|
const config: UserConfig = {
|
|
plugins: [
|
|
preact(),
|
|
paths(),
|
|
legacy({
|
|
targets: ['defaults', 'not IE 11'],
|
|
}),
|
|
devOnlyRouter(),
|
|
],
|
|
build: {
|
|
assetsDir: 'static',
|
|
rollupOptions: {
|
|
input: {
|
|
index: resolve(__dirname, 'index.html'),
|
|
post: resolve(__dirname, 'post.html'),
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
export default config
|