-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
40 lines (38 loc) · 1.01 KB
/
vite.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { defineConfig } from 'vite'
import uno from 'unocss/vite'
import * as fs from 'node:fs/promises'
export default defineConfig({
server: {
proxy: {
'/kmoni': {
target: 'http://www.kmoni.bosai.go.jp',
rewrite: (p) => p.slice(6),
},
},
},
plugins: [
uno(),
{
name: 'plugin-save-json',
configureServer(server) {
server.middlewares.use('/save', async (req, res) => {
let text = ''
req.addListener('data', (chunk) => {
text += chunk.toString()
})
req.on('end', async () => {
await fs.writeFile('positions.json', text)
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end('OK')
})
})
server.middlewares.use('/get', async (req, res) => {
const text = await fs.readFile('positions.json')
res.writeHead(200, { 'Content-Type': 'application/json' })
res.end(text)
return
})
},
},
],
})