LoginSignup
4
0

More than 3 years have passed since last update.

Nuxt.jsのローカルでのhttps起動をnuxt.config.jsの設定で行う

Posted at

概要

Nuxt.jsをローカルでhttps起動する際、起動スクリプトを作成する手順が検索すると引っかかるのですが、バージョンの関係か私のローカル環境では上手くいきませんでした。。ので起動スクリプトを使わずに、nuxt.config.jsの設定のみで起動する方法を紹介します。

前提

localhostに対するSSL証明書が、発行済みであることを前提とします。@yoshinboさんのNuxt.jsでlocalhostをSSL化する方法に記載の手順などを参考に、keyとcertファイルを作成してください。

参考

Example using HTTPS configuration

設定例

server/localhost配下に、上記で作成した証明書のファイルを配置しています。

nuxt.config.js
import path from "path";
import fs from "fs";

export default {
  server: {
    port: 3001, // デフォルト: 3000
    host: "localhost", // デフォルト: localhost
    https: {
      key: fs.readFileSync(
        path.resolve("server/localhost", "localhost-key.pem")
      ),
      cert: fs.readFileSync(path.resolve("server/localhost", "localhost.pem"))
    }
  }
};
4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0