节点,Express静态文件和动态路由

时间:2019-02-08 14:33:08

标签: javascript node.js express

我的静态图片无法在动态路由上投放。 我在这里读了多个线程,但是没有一个解决方案起作用。

//The files in public work but those in the images folder dont
const fileStorage = multer.diskStorage({
  destination: (req, file, cb) => {
    cb(null, 'images');
  },
  filename: (req, file, cb) => {
    cb(
      null,
      `${new Date().toISOString().replace(/:/g, '-')}` +
        '-' +
        file.originalname
    );
  }
});
app.use(express.static(path.join(__dirname, 'public')));
app.use('/images', express.static(path.join(__dirname, 'images')));;

//My routes
 router.get('/user-page', isAuth, userRouter.getUserPage);
router.get('/user-page/:userId', isAuth, userRouter.getUserPage);

0 个答案:

没有答案
相关问题