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

[http-server-javascript] Implement basic project scaffolding. #5906

Merged
merged 12 commits into from
Feb 12, 2025

Conversation

witemple-msft
Copy link
Member

Adds a new scaffolding command for http-server-js. To run it, a customer calls npx hsj-scaffold. It is opinionated, but uses some settings from tspconfig.yaml.

  • Generates a server entrypoint using either express or Node depending on whether tspconfig.yaml has express: true in the emitter options.
  • Generates a controller for each interface as a class that implements the business logic interface. For now, these controller methods simply throw 501 Not Implemented.
  • Creates a suitable tsconfig.json to compile the project.
  • Modifies package.json with scripts to build and start the server.
  • Adds vscode tasks/launch configurations for debugging.

Some changes to the generator itself were required:

  • Added a new helper module, helpers/http, that defines an HttpResponder as an object containing a function that can respond to an HTTP request. If the business logic implementations throw an object that is an HttpResponder, then it will be used to respond to the request instead of the default onInternalError handler. This makes it easy for any route controller handler to construct and reply with any error they like without having to satisfy the type checker.

@azure-sdk
Copy link
Collaborator

azure-sdk commented Feb 7, 2025

All changed packages have been documented.

  • @typespec/http-server-javascript
Show changes

@typespec/http-server-javascript - feature ✏️

Implement basic project scaffolding.

@azure-sdk
Copy link
Collaborator

azure-sdk commented Feb 7, 2025

You can try these changes here

🛝 Playground 🌐 Website 📚 Next docs 🛝 VSCode Extension

Copy link
Member

@allenjzhang allenjzhang left a comment

Choose a reason for hiding this comment

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

Please fix npm install as discussed.

@witemple-msft
Copy link
Member Author

@allenjzhang The npm install issue on windows should be fixed by using shell: true when the platform is win32 (this is an annoying, evergreen Node programming bug that I always hit -- spawn and execFile cannot execute batch scripts, which npm is on windows).

@markcowl I'm going to resolve the comments per our discussion. There's more work to be done here around scaffolding hooks and proper use of the compiler APIs.

@witemple-msft witemple-msft added this pull request to the merge queue Feb 11, 2025
Merged via the queue into microsoft:main with commit e6aa3e1 Feb 12, 2025
24 checks passed
@witemple-msft witemple-msft deleted the witemple-msft/hsj-scaffold branch February 12, 2025 00:10
dmnorc pushed a commit to dmnorc/typespec that referenced this pull request Feb 18, 2025
…oft#5906)

Adds a new scaffolding command for http-server-js. To run it, a customer
calls `npx hsj-scaffold`. It is opinionated, but uses some settings from
tspconfig.yaml.

- Generates a server entrypoint using either express or Node depending
on whether tspconfig.yaml has `express: true` in the emitter options.
- Generates a controller for each interface as a class that implements
the business logic interface. For now, these controller methods simply
throw 501 Not Implemented.
- Creates a suitable tsconfig.json to compile the project.
- Modifies package.json with scripts to build and start the server.
- Adds vscode tasks/launch configurations for debugging.

Some changes to the generator itself were required:
- Added a new helper module, `helpers/http`, that defines an
`HttpResponder` as an object containing a function that can respond to
an HTTP request. If the business logic implementations throw an object
that is an HttpResponder, then it will be used to respond to the request
instead of the default `onInternalError` handler. This makes it easy for
any route controller handler to construct and reply with any error they
like without having to satisfy the type checker.
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.

4 participants