@@ -21,8 +21,7 @@ var defaultConfig = {
21
21
<!--inject-config-->
22
22
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
23
23
</body>
24
- </html>` ,
25
- context : './'
24
+ </html>`
26
25
}
27
26
28
27
function loadConfig ( config ) {
@@ -37,13 +36,12 @@ function loadConfig (config) {
37
36
module . exports = function ( path , configFile , port ) {
38
37
let config = defaultConfig
39
38
const pkg = util . pkg ( )
40
- let ctx = util . cwd ( )
39
+ let ctx = util . cwd ( '.' )
41
40
42
41
path = path || './'
43
42
44
43
if ( configFile ) {
45
44
config = loadConfig ( configFile )
46
- ctx = config . context || ctx
47
45
config . template = / \. h t m l $ / . test ( config . template )
48
46
? util . read ( util . resolve ( ctx , config . template ) )
49
47
: config . template
@@ -57,16 +55,23 @@ module.exports = function (path, configFile, port) {
57
55
var renderer = new Renderer ( Object . assign ( defaultConfig , config ) )
58
56
var server = connect ( )
59
57
58
+ server . use ( serveStatic ( path ) )
60
59
server . use ( function ( req , res ) {
61
- renderer . renderToString ( req . url )
62
- . then ( function ( html ) {
63
- res . end ( html )
64
- } )
65
- . catch ( function ( err ) {
66
- res . end ( util . read ( util . resolve ( path , 'index.html' ) ) )
67
- } )
60
+ serveStatic ( path ) ( req , res , function ( ) {
61
+ if ( / \. ( j p g | j p e g | g i f | p n g | s v g | i c o | m p 4 | w e b m | o g g | o g v | j s | c s s | m d ) (?: \? v = [ 0 - 9 . ] + ) ? $ / . test ( req . url ) ) {
62
+ res . writeHead ( 404 )
63
+ res . end ( )
64
+ }
65
+ renderer . renderToString ( req . url )
66
+ . then ( function ( html ) {
67
+ res . end ( html )
68
+ } )
69
+ . catch ( function ( err ) {
70
+ res . writeHead ( 404 )
71
+ res . end ( )
72
+ } )
73
+ } )
68
74
} )
69
- server . use ( serveStatic ( path ) )
70
75
server . listen ( port || 4000 )
71
76
72
77
const msg = '\n'
0 commit comments