Egg: 如何配置egg-static,使用浏览器访问/public/ 输出/public/index.html

Created on 7 Oct 2017  ·  3Comments  ·  Source: eggjs/egg

  • Node Version:
  • Egg Version:[email protected]
  • Plugin Name:
  • Plugin Version:
  • Platform:
  • Mini Showcase Repository:
    /public/index.html可以, /public/ 404

config.default.js是这样的:

'use strict';

module.exports = appInfo => {
  const config = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1507383951618_490';

  // add your config here
  config.middleware = [];
  config.static = {
      maxAge: 31536000,
      prefix: '/public',
      index: 'index.html'
  }
  return config;
};

All 3 comments

不支持目录

@popomore
不支持目录可以理解,但是首页也是这样404总不行吧?
http://localhost:7001/ => 404
http://localhost:7001/index.html => OK

Solved!
import { controller, get, provide } from 'midway';

@provide()
@controller('/')
export class HomeController {

@get('/')
async index(ctx) {
ctx.redirect('/index.html')
}
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Ailein picture Ailein  ·  3Comments

Quekie picture Quekie  ·  3Comments

wujianling picture wujianling  ·  3Comments

yuu2lee4 picture yuu2lee4  ·  3Comments

AkashiX picture AkashiX  ·  4Comments