-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.dev.js
More file actions
41 lines (36 loc) · 1.31 KB
/
server.dev.js
File metadata and controls
41 lines (36 loc) · 1.31 KB
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
/**
* Local development server for /api/compress and /api/blob-upload.
* Mirrors the Vercel serverless functions locally.
*
* Usage:
* node server.dev.js (port 3001 by default)
* PORT=4000 node server.dev.js
*
* The Vite dev server proxies /api → http://localhost:3001
*
* Note: /api/blob-upload returns { localMode: true } when BLOB_READ_WRITE_TOKEN
* is not set — the client automatically falls back to legacy multipart upload.
*/
import http from 'http'
import compressHandler from './api/compress.js'
import blobUploadHandler from './api/blob-upload.js'
const PORT = process.env.PORT || 3001
const server = http.createServer((req, res) => {
const url = req.url?.split('?')[0]
if (url === '/api/compress' || url === '/api/compress/') {
return compressHandler(req, res)
}
if (url === '/api/blob-upload' || url === '/api/blob-upload/') {
return blobUploadHandler(req, res)
}
res.writeHead(404)
res.end('Not found')
})
server.listen(PORT, () => {
console.log(`[dev-api] Listening on http://localhost:${PORT}`)
console.log('[dev-api] POST /api/compress is ready')
console.log('[dev-api] POST /api/blob-upload is ready')
if (!process.env.BLOB_READ_WRITE_TOKEN) {
console.log('[dev-api] Note: BLOB_READ_WRITE_TOKEN not set — using localMode (multipart upload)')
}
})