Skip to content

Add port option to qiita.config.json #43

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

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
dist
node_modules
tmp
.github/workflows/publish.yml
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ npx qiita version
設定できるオプションは以下の通りです。

- includePrivate: 限定共有記事を含めるかどうかを選べます。デフォルトは`false`です。
- port: `qiita preview`コマンドで利用するポートを指定できます。デフォルトは`8888`です。

## オプション

Expand Down
3 changes: 3 additions & 0 deletions src/lib/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ describe("config", () => {
beforeEach(() => {
const userConfigData = {
includePrivate: true,
port: 9999,
};
resetFiles();
setFile(userConfigFilePath, JSON.stringify(userConfigData, null, 2));
Expand All @@ -233,6 +234,7 @@ describe("config", () => {
const userConfig = await config.getUserConfig();
expect(userConfig).toStrictEqual({
includePrivate: true,
port: 9999,
});
});
});
Expand All @@ -246,6 +248,7 @@ describe("config", () => {
const userConfig = await config.getUserConfig();
expect(userConfig).toStrictEqual({
includePrivate: false,
port: 8888,
});
});
});
Expand Down
2 changes: 2 additions & 0 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface Options {

type UserConfig = {
includePrivate: boolean;
port: number;
};

class Config {
Expand Down Expand Up @@ -106,6 +107,7 @@ class Config {
async getUserConfig() {
const defaultConfig = {
includePrivate: false,
port: 8888,
} as UserConfig;

if (fsSync.existsSync(this.getUserConfigFilePath())) {
Expand Down
6 changes: 3 additions & 3 deletions src/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { AssetsRouter } from "./api/assets";
import { EmojiRouter } from "./api/emoji";
import { ItemsRouter } from "./api/items";
import { ReadmeRouter } from "./api/readme";
import { config } from "../lib/config";

export async function startServer() {
const app = express();
Expand All @@ -30,9 +31,8 @@ export async function startServer() {
app.use("*", express.static(path.join(__dirname, "../public/index.html")));

const server = createServer(app);
const port = process.env.QIITA_CLI_PORT
Copy link
Member

Choose a reason for hiding this comment

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

QIITA_CLI_PORT環境変数消します?

Copy link
Member Author

Choose a reason for hiding this comment

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

PRに記載の通り、削除で良いかなと思っています

Copy link
Member

@ohakutsu ohakutsu Jul 25, 2023

Choose a reason for hiding this comment

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

あ、見落としてました、
OKです!

? parseInt(process.env.QIITA_CLI_PORT, 10)
: 8888;
const userConfig = await config.getUserConfig();
const port = userConfig.port;
const host = "localhost";

return new Promise<Server>((resolve) => {
Expand Down