Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support unix socket or port for functions server #1689

Merged
merged 5 commits into from
Feb 4, 2021
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions packages/api-server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
import { rmSync } from 'fs'
import path from 'path'

import requireDir from 'require-dir'
Expand All @@ -7,8 +8,9 @@ import yargs from 'yargs'
import { server, setLambdaFunctions } from './http'
import { requestHandler } from './requestHandlers/awsLambda'

const { port, functions } = yargs
const { port, functions, socket } = yargs
.option('port', { default: 8911, type: 'number' })
.option('socket', { type: 'string' })
.option('functions', {
alias: 'f',
required: true,
Expand Down Expand Up @@ -36,10 +38,17 @@ const serverlessFunctions = requireDir(path.join(process.cwd(), functions), {
})

try {
server({ requestHandler }).listen(port, () => {
console.log(`http://localhost:${port}`)
const app = server({ requestHandler }).listen(socket || port, () => {
if (socket) console.log(socket)
else console.log(`http://localhost:${port}`)
setLambdaFunctions(serverlessFunctions)
})

process.on('exit', () => {
app.close(() => {
if (socket) rmSync(socket)
})
})
} catch (e) {
console.error(e)
process.exit(1)
Expand Down