Help us understand the problem. What is going on with this article?

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

概要

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"))
    }
  }
};
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした