LoginSignup
1
0

More than 5 years have passed since last update.

Expressの公開ディレクトリを追加する

Posted at

今作っているシステムはプラグイン的にMVCを1つのモジュールとして配布できるのですが、モジュールによってはWebブラウザ向けのJavaScript/CSSも配布したいことがあります。

そこでExpressの公開ディレクトリを動的に追加します。

app.use('public2', express.static('modules_public_path'));

こうすると http://example.com/public2 も公開ディレクトリになります。後はこの中に index.js や index.css を作っていけば良いだけです。public2というのがキーになるので、同じ名前だと上書きしてしまうと思います。後、

app.use('/admin/public2', express.static('modules_public_path'));

みたいに階層も使えるので便利です。

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