LoginSignup
8
8

More than 5 years have passed since last update.

Herokuで静的ファイルに直接アクセスする方法

Posted at

以下ようなURLHerokuにデプロイした静的ファイルに以下のように直接アクセスしたい機会があったので、やり方をまとめておきます。
http://exmaple.herokuapp.com/example.html"

GitHubに各言語での雛形が置いてありました。
今回はNode.jsを利用した場合について記述していきます。

リポジトリをクローン

最初に以下のコマンドでリポジトリをクローンします。

$ git clone https://github.com/nulltask/heroku-static-provider.git my-site
$ cd my-site

静的ファイルを配置

アクセスしたいファイルをpublicディレクトリに配置します。
今回は以下のhelloworld.htmlを配置してみます。

helloworld.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  Hello World!
</body>
</html>

Herokuへデプロイ

Herokuへリポジトリをデプロイします。

$ heroku create
$ git commit -a -m 'some commit message'
$ git push -u heroku master

静的ファイルにアクセス

以下のようなURLでアクセスすれば、Herokuにデプロイした静的ファイルにアクセス出来ます。
(hogehogeは任意の文字列)
http://{hogehoge}.herokuapp.com/helloworld.html

参考

Serving static files in Express
http://expressjs.com/starter/static-files.html

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