Skip to content

Commit ac60f62

Browse files
authored
Merge pull request #43 from increments/add-port-config
Add port option to qiita.config.json
2 parents 4d79ea3 + 872d8d6 commit ac60f62

File tree

5 files changed

+10
-3
lines changed

5 files changed

+10
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
dist
33
node_modules
44
tmp
5+
.github/workflows/publish.yml

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ npx qiita version
224224
設定できるオプションは以下の通りです。
225225

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

228229
## オプション
229230

src/lib/config.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ describe("config", () => {
224224
beforeEach(() => {
225225
const userConfigData = {
226226
includePrivate: true,
227+
port: 9999,
227228
};
228229
resetFiles();
229230
setFile(userConfigFilePath, JSON.stringify(userConfigData, null, 2));
@@ -233,6 +234,7 @@ describe("config", () => {
233234
const userConfig = await config.getUserConfig();
234235
expect(userConfig).toStrictEqual({
235236
includePrivate: true,
237+
port: 9999,
236238
});
237239
});
238240
});
@@ -246,6 +248,7 @@ describe("config", () => {
246248
const userConfig = await config.getUserConfig();
247249
expect(userConfig).toStrictEqual({
248250
includePrivate: false,
251+
port: 8888,
249252
});
250253
});
251254
});

src/lib/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ interface Options {
1414

1515
type UserConfig = {
1616
includePrivate: boolean;
17+
port: number;
1718
};
1819

1920
class Config {
@@ -106,6 +107,7 @@ class Config {
106107
async getUserConfig() {
107108
const defaultConfig = {
108109
includePrivate: false,
110+
port: 8888,
109111
} as UserConfig;
110112

111113
if (fsSync.existsSync(this.getUserConfigFilePath())) {

src/server/app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { AssetsRouter } from "./api/assets";
99
import { EmojiRouter } from "./api/emoji";
1010
import { ItemsRouter } from "./api/items";
1111
import { ReadmeRouter } from "./api/readme";
12+
import { config } from "../lib/config";
1213

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

3233
const server = createServer(app);
33-
const port = process.env.QIITA_CLI_PORT
34-
? parseInt(process.env.QIITA_CLI_PORT, 10)
35-
: 8888;
34+
const userConfig = await config.getUserConfig();
35+
const port = userConfig.port;
3636
const host = "localhost";
3737

3838
return new Promise<Server>((resolve) => {

0 commit comments

Comments
 (0)