Skip to content

feat: add custom formatURL support#4

Merged
pi0 merged 4 commits intopithings:mainfrom
mickaelalvs:feat/open-file-on-start
Apr 24, 2026
Merged

feat: add custom formatURL support#4
pi0 merged 4 commits intopithings:mainfrom
mickaelalvs:feat/open-file-on-start

Conversation

@mickaelalvs
Copy link
Copy Markdown
Contributor

@mickaelalvs mickaelalvs commented Apr 22, 2026

❓ Context

Adds a formatURL callback option to startCodeServer / createCodeServer, allowing callers to customize the URL returned by the server before it is handed back to the consumer.

const handle = await startCodeServer({
  defaultFolder: '/my/project',
  formatURL: (url) => {
    // open a specific file on startup
    url.searchParams.set(
      'payload',
      JSON.stringify([['openFile', `vscode-remote://remote/my/project/src/index.ts`]])
    )
    return url
  },
})

The callback receives the base URL after auth params (tkn) have been applied. It can return a modified URL, a plain string, or undefined (keep the original URL unchanged).

This replaces the previous openFile option with a more generic primitive — callers can now inject any URL parameter VS Code supports (payload, folder, etc.) without requiring dedicated options in coderaft itself.

@mickaelalvs
Copy link
Copy Markdown
Contributor Author

📝 note: CI fixed with #5 😊

Comment thread lib/src/server.ts Outdated
const baseUrl = new URL(`http://localhost:${actualPort}${basePath}/`);
if (handler.connectionToken) baseUrl.searchParams.set("tkn", handler.connectionToken);
if (opts.openFile) {
// VS Code's workbench reads `payload` as Map entries: new Map(JSON.parse(payload)).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if it might be more useful to instead add a generic formatURL(url: URL): string | URL | undefined callback option that accepts original url and allows customizing it. I guess we might have more options than openFile

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that’s exactly what I thought after creating this PR, I’ve already seen other use cases 😅 I’ll have a look!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pi0 I've tried to make the function more generic so that we can add more options 😊

@pi0 pi0 changed the title feat: add openFile option to startCodeServer feat: add custom formatURL support Apr 24, 2026
Copy link
Copy Markdown
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thnx!

@pi0 pi0 merged commit 41c4129 into pithings:main Apr 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants