caderek / gramma

command-line grammar checker
https://caderek.github.io/gramma/
ISC License
251 stars 18 forks source link

PORT support on `gramma server start` #29

Closed azu closed 2 years ago

azu commented 2 years ago

Is your feature request related to a problem? Please describe.

Currently, port number is hardcoded 8081.

https://github.com/caderek/gramma/blob/3023e3ae7db87c9acd3989762669d229894cae83/src/server/startServer.js#L35-L37

Describe the solution you'd like I want to use another port number like following.

gramma server start --port 12345

Describe alternatives you've considered

PORT=12345 gramma server start

Additional context

📝 Current gramma server start does not show the port number of languagetools server. if the port number is conflicted, the user can not know the local server url.

$ gramma server start
Starting local API server...
Waiting for local API server...
Waiting for local API server...
API server started! PID: 55069
caderek commented 2 years ago

It's a bit different - port is not hard-coded - the 8081 is a default value - Gramma will check if it is available and will find another free port if needed (that's what portfinder does). If it's not enough I can add a port parameter, but I try to keep the API minimal (but it could be a valid use case).

if the port number is conflicted, the user can not know the local server url.

Local server url (with the correct port) is always available at api_url key in the global config.

PS I saw your PR, looks good, but I'm still not sure if it's a must-have feature.

azu commented 2 years ago

Fmm, 8081 is popular port. Often port is conflicted and use another port like 8082.

I want to use gramma with local api server in my computer. It means that I need to write the port into config or source code.

const gramma = require("gramma")

gramma
  .check("Some text to check.", {
    api_url: "http://localhost:13451/v2/check" // if the port is random, it is hard to use
  })
  .then(console.log)

It requres that always use specific unused port like 13451 in my computer.

For example, I've created textlint-rule/textlint-rule-gramma. This tool have used gramma. If the user want to use local gramma, how to set the api_url? "api_url": "http://localhost:8081/v2/check" will be broken if 8081 is used by another program.

Of course, I can stop the another program that use 8081. However, --port is common feature in server program. Actually, LanguageTool server support it.

caderek commented 2 years ago

Ok, it's a valid concern - I will merge the PR, but have to tweak it a bit before I update npm package and binaries.

caderek commented 2 years ago

New version is available!

azu commented 2 years ago

Thanks!