-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.bun.imba
52 lines (41 loc) · 1.31 KB
/
server.bun.imba
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
41
42
43
44
45
46
47
48
49
50
51
52
const fs = require("fs")
const path = require("path")
const getAllFiles = do(dirPath, arrayOfFiles)
const files = fs.readdirSync(dirPath)
arrayOfFiles = arrayOfFiles || []
files.forEach(do(file)
if (fs.statSync(dirPath + "/" + file).isDirectory())
arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles)
else
arrayOfFiles.push(path.join(__dirname, dirPath, "/", file))
)
return arrayOfFiles
import { Hono } from 'hono'
import { logger } from 'hono/logger'
import { cors } from 'hono/cors'
import { etag } from 'hono/etag'
import { serveStatic } from 'hono/serve-static'
var mime = require('mime-types')
const app = new Hono()
app.use('*', logger())
app.use('*', cors())
# app.use('*', etag())
app.get '/reload', do |c|
const file = fs.statSync(path.join(__dirname, "/", 'server.bun.js'))
const query = c.req.query('q')
console.log "{file.mtime_ms}", query
c.json(
reload: "{file.mtime_ms}" !== query
q: file.mtime_ms
)
app.get '*', do |c|
const file = getAllFiles('public').find(do |match| c.req.url.match match.split('/')[-1])
const result = new Response(Bun.file(file || "./public/index.html"))
const body = await result.text()
file ? c.body(body, 200, {'content-type': mime.lookup(file) }) : c.html(body)
export default {
port: Bun.env.PORT || 3000
fetch: do |req|
app.fetch req
}