Skip to content
Open
Changes from all 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: 10 additions & 5 deletions packages/micro/src/bin/micro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { RequestHandler } from '../lib';

// Check if the user defined any options
const args = arg({
'--listen': parseEndpoint,
'--listen': [parseEndpoint],
'-l': '--listen',
'--help': Boolean,
'--version': Boolean,
Expand Down Expand Up @@ -83,7 +83,7 @@ if (args['--version']) {

if (!args['--listen']) {
// default endpoint
args['--listen'] = [String(3000)];
args['--listen'] = [[String(3000)]];
}

let file = args._[0];
Expand Down Expand Up @@ -142,15 +142,15 @@ function registerShutdown(fn: () => void) {
process.on('exit', wrapper);
}

function startEndpoint(module: RequestHandler, endpoint: string) {
function startEndpoint(module: RequestHandler, endpoint: string[]) {
const server = new http.Server(serve(module));

server.on('error', (err) => {
console.error('micro:', err.stack);
process.exit(1);
});

server.listen(endpoint, () => {
const handler = () => {
const details = server.address();
registerShutdown(() => {
console.log('micro: Gracefully shutting down. Please wait...');
Expand All @@ -167,7 +167,12 @@ function startEndpoint(module: RequestHandler, endpoint: string) {
} else {
console.log('micro: Accepting connections');
}
});
};

if(endpoint.length === 2)
server.listen(parseInt(endpoint[0]||''), endpoint[1], handler);
else
server.listen(endpoint[0], handler);
}

async function start() {
Expand Down