まじごみ日記

パチスロ・アニメ・特撮好きの日記です。最近の趣味は筋トレ。

クソWebアプリ制作日記 その6

これまで

Heroku Postgresの導入と、テーブル作成ができた。次はこれを操作するため「vue-cli-plugin-express」でAPIサーバを作る。

そしてテレワークが始まったが、予想通り全く集中できない。
テレワークは、「ちょうどよい作業量」で「常に作業を監視されている」状態じゃないと、絶対にうまくいかないと断言できる。
なぜなら、暇だとサボるし、残業するくらい忙しいと「どうせ残業するし」という気持ちで結局日中サボる。 ちょうどよい作業量だと、多少の進捗の遅れは後でどうとでもできてしまうので、結局サボる。

サボらないようにするには、これはもうサボるやつを徹底的に監視し続けるしかない。 一時間おきに状況報告とか、常にテレビ会議繋ぎっぱなしとか。 それには労力が掛かるので、忙しいときにはできないし、暇なときにはバカバカしくてやらない。 結局、「ちょうどよい作業量」で「常に作業を監視されている」ときしかうまくいかないのだ。

ちなみに、サボった本人も良いことは一つもない。結局サボった分の尻拭いをするのはサボった本人だから。(自分で尻拭い出来なくなるレベルのサボり方をするやつは全員死んでる前提)

誰かに監視されていないと、まともに作業できない人間は大勢いるのだ。
世の中のすごい人たち(なんか起業したりする人ね)は、皆が自分と同じように自主的に行動できる人間ばかりではないこを知るべきだ。 業務時間中にラノベを一冊まるまる読んでしまう、そんな業務態度のヤツを寛大に受け入れるために。
・・・後ろめたさはある。明日は集中しよ!

vue-cli-plugin-express

プラグインのインストール。

C:\work\sampleProject\sample-pj>vue add express

�  Installing vue-cli-plugin-express...


> nodemon@1.19.4 postinstall C:\work\sampleProject\sample-pj\node_modules\nodemon
> node bin/postinstall || exit 0

+ vue-cli-plugin-express@1.0.2
added 78 packages from 33 contributors in 66.579s

42 packages are looking for funding
  run `npm fund` for details

✔  Successfully installed plugin: vue-cli-plugin-express

? Should serve vue app? Yes
? Where will be located your server? ./srv

�  Invoking generator for vue-cli-plugin-express...
⚓  Running completion hooks...

✔  Successfully invoked generator for plugin: vue-cli-plugin-express

インストールとセットアップはできたみたい。

srv/index.jsが作られたので、これを編集して起動してみる。

C:\work\sampleProject\sample-pj>npm run express

> sample-pj-new@0.1.0 express C:\work\sampleProject\sample-pj
> vue-cli-service express:watch



 DONE  Wed Apr 15 2020 20:41:18 GMT+0900 (GMT+09:00)

  ♻️  Server running at:
    - Local:   http://localhost:3000/
    - Network: http://192.168.11.9:3000/


  ⚙  You're in development mode. to start the application, run npm run serve.

  � Fallback to this server enabled: you can use relative routes in your code!

  � Api routes found:
    - /gomi: GET

とりあえず動かすことはできた。

次に「Heroku Postgres」に作成したテーブルを参照してみる。
「node-postgres」をインストールする。

C:\work\sampleProject\sample-pj>npm install pg --save
npm WARN vue-cli-plugin-express@1.0.2 requires a peer of @vue/cli-service@^3.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN vue-cli-plugin-express@1.0.2 requires a peer of @vue/cli-shared-utils@^3.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.12 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.12: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ pg@8.0.2
added 15 packages from 6 contributors and audited 27944 packages in 32.177s

42 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

ムム、怪しいワーニングが出た。ここは思考停止で無視して進めてみる。

以下のリファレンスを見て、接続してみる。

Heroku Postgres | Heroku Dev Center

うまくいかず。証明書エラーのよう。

(node:10988) UnhandledPromiseRejectionWarning: Error: self signed certificate
    at TLSSocket.onConnectSecure (_tls_wrap.js:1474:34)
    at TLSSocket.emit (events.js:310:20)
    at TLSSocket.EventEmitter.emit (domain.js:482:12)
    at TLSSocket._finishInit (_tls_wrap.js:917:8)
    at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:687:12)
(node:10988) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:10988) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

公式リファレンスには「sslmode=requireを記載しろ!」みたいなことが書いているけど、どこに追加してもダメ。
「sslfactory=org.postgresql.ssl.NonValidatingFactory」の設定も試したが、ダメ。
色々試して・・・数時間。

うおーー!完全に詰まった!!

思ったこと

やればやるほど絶望する。わからないことが多すぎ。