Skip to content

Commit

Permalink
feature: add inject option and properly pass server setup object
Browse files Browse the repository at this point in the history
  • Loading branch information
stagas committed Feb 4, 2022
1 parent 7929ef2 commit 4dbae6a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const runInClient = async (setup: ClientSetup, fn: () => unknown) => {
let errorHook!: () => void
const errorPromise = new Promise<void>((_, reject) => (errorHook = reject))

const server = await createServer({ root: setup.root ?? process.cwd(), errorHook })
const server = await createServer({ ...setup, root: setup.root ?? process.cwd(), errorHook })

setup.launchOptions ??= {}
setup.launchOptions.args ??= []
Expand Down
3 changes: 2 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface ContentResponse {
export interface ServerSetup {
errorHook: (error: Error) => void
root: string
inject?: string
buildOptions?: Parameters<typeof buildSync>[0]
}

Expand Down Expand Up @@ -59,7 +60,7 @@ export const createServer = async (setup: ServerSetup) => {
}
const contentType = mime.contentType(path.basename(filename))
res.setHeader('Content-Type', contentType || 'application/octet-stream')
res.end(contents)
res.end((setup.inject ?? '') + contents)
} catch (error) {
// console.log(error)
res.statusCode = 400
Expand Down

0 comments on commit 4dbae6a

Please sign in to comment.