@@ -9,15 +9,15 @@ const tryRequire = require('try-require');
99const HookEvent = require ( './HookEvent' ) ;
1010const staticServer = require ( './staticServer' ) ;
1111
12- module . exports = function ( options = { } , api ) {
12+ module . exports = function ( opts = { } , api ) {
1313 const logger = api . logger ;
14- const isDev = options . isDev || false ;
15- const onlyNode = options . onlyNode || false ;
14+ const isDev = opts . isDev || false ;
15+ const onlyNode = opts . onlyNode || false ;
1616 if ( isDev ) {
1717 logger . info ( 'Dev Server Start...' ) ;
1818 }
1919
20- const serverConfig = options . serverConfig ;
20+ const serverConfig = opts . serverConfig ;
2121
2222 const app = new Koa ( ) ;
2323 // 兼容koa1的中间件
@@ -49,8 +49,8 @@ module.exports = function(options = {}, api) {
4949 applyHooks ( _HookEvent , 'after' ) ;
5050
5151 if ( isDev ) {
52- const compiler = options . compiler || false ;
53- const devOptions = options . devOptions || { } ;
52+ const compiler = opts . compiler || false ;
53+ const devOptions = opts . devOptions || { } ;
5454 if ( ! onlyNode && ! ! compiler ) {
5555 const koaWebpackMiddleware = require ( './koa-webpack-middleware' ) ;
5656 app . use ( koaWebpackMiddleware . devMiddleware ( compiler , devOptions ) ) ;
@@ -61,14 +61,24 @@ module.exports = function(options = {}, api) {
6161 const { contentBase, options = { } } = serverConfig ;
6262 const koaStatic = staticServer ( contentBase , options ) ;
6363 if ( koaStatic ) {
64+ if ( opts . type === 'vusion' ) {
65+ const config = opts . config ;
66+ const prePath = contentBase . replace ( config . root , '' ) ;
67+ app . use ( ( ctx , next ) => {
68+ if ( ctx . url ) {
69+ ctx . url = ctx . url . replace ( prePath , '' ) ;
70+ }
71+ return next ( ) ;
72+ } ) ;
73+ }
6474 app . use ( koaStatic ) ;
6575 }
6676 }
6777
6878 api . applyPluginHooks ( 'onServerInitDone' , { app, config : serverConfig } ) ;
6979
70- const port = options . port || serverConfig . port || 8888 ;
71- const host = options . host || serverConfig . host || 'localhost' ;
80+ const port = opts . port || serverConfig . port || 8888 ;
81+ const host = opts . host || serverConfig . host || 'localhost' ;
7282 return new Promise ( ( resolve , reject ) => {
7383 app . listen ( port , host === 'localhost' ? '0.0.0.0' : host , err => {
7484 if ( err ) {
0 commit comments