Skip to content

Commit bf811eb

Browse files
authored
Local serve public files (#15)
* Serve public files * Log * Log * Fix * CLeanup
1 parent 3048743 commit bf811eb

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Plugins/VercelPackager/Server/server.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const http = require('http')
2+
const path = require('path')
3+
const fs = require('fs')
24
const port = Number(process.argv[2] || 7676)
35

46
async function invoke(payload) {
@@ -26,7 +28,20 @@ async function readBody(stream) {
2628
})
2729
}
2830

31+
function serveStaticFile(req, res) {
32+
const localPath = path.join(process.env.SWIFT_PROJECT_DIRECTORY, 'public', req.url)
33+
const data = fs.readFileSync(localPath)
34+
res.writeHead(200, {})
35+
res.end(data)
36+
}
37+
2938
const server = http.createServer(async (req, res) => {
39+
try {
40+
serveStaticFile(req, res)
41+
return
42+
} catch (err) {
43+
// ignore
44+
}
3045
try {
3146
const method = req.method
3247
const path = req.url

Plugins/VercelPackager/VercelOutput.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ public struct VercelOutput {
9999
arguments: [
100100
projectDirectory.appending([".build", "checkouts", "Vercel", "Plugins", "VercelPackager", "Server", "server.js"]).string,
101101
port
102-
]
102+
],
103+
environment: ["SWIFT_PROJECT_DIRECTORY": projectDirectory.string]
103104
)
104105
}
105106

0 commit comments

Comments
 (0)