-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
23 lines (19 loc) · 726 Bytes
/
index.js
File metadata and controls
23 lines (19 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import edge from 'edge.js'
import { createServer } from 'node:http'
import { createReadStream } from 'node:fs'
edge.mount(new URL('./views', import.meta.url))
createServer(async (req, res) => {
if (req.url === '/app.js') {
res.setHeader('content-type', 'application/javascript')
return createReadStream(new URL('./public/app.js', import.meta.url)).pipe(res)
}
if (req.url === '/style.css') {
res.setHeader('content-type', 'text/css')
return createReadStream(new URL('./public/style.css', import.meta.url)).pipe(res)
}
const html = await edge.render('index')
res.setHeader('content-type', 'text/html')
res.end(html)
}).listen(3000, () => {
console.log('Running on http://localhost:3000')
})