0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

React Router v7アプリケーションをIISにデプロイしたかったのでIIS上でホストしてみた

Posted at

IISにNext.jsがデプロイできるという事で、React Router v7でも試してみた。
参考サイト
https://qiita.com/utsubo-daisuki/items/1b48dd69668dc70d2f2a
https://nodejs.keicode.com/nodejs/using-platformhandler-to-host-nodejs-on-iis.php

概要

IIS拡張モジュール「HttpPlatformHandler」を使うと、IISからnode.exeを起動してHTTP要求をNodeプロセスに処理させることができる。
NodeプロセスでReact Routerを起動させる設定をすればOK。

HttpPlatformHandler インストール

https://www.iis.net/downloads/microsoft/httpplatformhandler
からダウンロード(httpPlatformHandler_amd64.msiなど)して実行する。

React Router 側の設定

今回はbasedirを / にするので特に設定なし。
以下のコマンドでビルドした。

pnpm run build

IISの設定

C:\projects\rr に、上記で作成したbuildフォルダとpackage.jsonを配置。
(build内にはclientとserverフォルダがある)
最初は pnpm install したが、node_module内のハードリンクをIISの実行ユーザでうまく読み込めずエラーとなってしまったため、npm install で node_moduleフォルダを作成した。
また、IISのWebサイトの物理パスを C:\projects\rr に変更した。

web.config

C:\projects\rr フォルダ内にweb.configファイルを作成し、以下の内容とした。
この後、IISのサービスを再起動した。

web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add
                name="httpPlatformHandler" 
                path="*" 
                verb="*" 
                modules="httpPlatformHandler"
                resourceType="Unspecified" />
        </handlers>
        <httpPlatform 
            processPath="C:\Programs\nodejs\node.exe"
            arguments="C:\projects\rr\node_modules\@react-router\serve\dist\cli.js C:\projects\rr\build\server\index.js"
            stdoutLogEnabled="true"
            stdoutLogFile="C:\projects\rr\logs\stdout">
            <environmentVariables>
                <environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
            </environmentVariables>
        </httpPlatform>
    </system.webServer>
</configuration>

実行確認

ブラウザで、下記にアクセス。
http://localhost/
React Routerの画面が表示されれば成功!

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?