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?

More than 5 years have passed since last update.

Expressで動的にviewsを変更する

0
Posted at

今作っているシステムで、プラグインのような形でMVCを一つのパッケージとして配布できるようにしているのですが、そのためにはビューのディレクトリをコントローラ側で動的に変更する必要がありました。

ということでやり方。

var express = require('express');
var router = express.Router();

router.all('*',  (req, res, next) => {
  req.app.set('views', __dirname + '/views/');
});

requestの中にappが入っているんですね。後はそれを動的にsetで変更してあげればOK。

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?