File tree Expand file tree Collapse file tree 10 files changed +39
-21
lines changed
Expand file tree Collapse file tree 10 files changed +39
-21
lines changed Original file line number Diff line number Diff line change @@ -71,14 +71,27 @@ async function initializeApp () {
7171 try {
7272 const vite = require ( 'vite' )
7373 viteServer = await vite . createServer ( {
74- server : { middlewareMode : true } ,
74+ server : {
75+ middlewareMode : true ,
76+ fs : {
77+ strict : true , // Strict file serving
78+ allow : [ __dirname ] // Only allow serving from the project root
79+ }
80+ } ,
7581 appType : 'custom' ,
76- root : __dirname , // Ensure root is set
77- base : '/'
82+ root : __dirname ,
83+ base : '/.vite/' // Set custom base path for Vite assets
7884 } )
79- // Use vite's connect instance as middleware *before* anything else
80- app . use ( viteServer . middlewares )
81- logger . info ( 'Vite middleware enabled.' )
85+
86+ // Only use Vite middleware for paths that start with /.vite/
87+ app . use ( ( req , res , next ) => {
88+ if ( req . path . startsWith ( '/.vite/' ) ) {
89+ return viteServer . middlewares ( req , res , next )
90+ }
91+ next ( )
92+ } )
93+
94+ logger . info ( 'Vite middleware enabled for /.vite/ path only.' )
8295 } catch ( e ) {
8396 logger . error ( 'Failed to create Vite server:' , e )
8497 process . exit ( 1 )
Original file line number Diff line number Diff line change @@ -68,10 +68,10 @@ function getViteAssets (entryName) {
6868 console . warn ( `Vite manifest entry not found for: ${ entryKey } ` )
6969 }
7070 } else {
71- // In development, Vite handles everything through its dev server
72- assets . js . push ( `/@vite/client` ) // Vite HMR client
73- // Request the actual file path relative to the project root
74- assets . js . push ( `/public/js/${ entryName } .js` )
71+ // In development, Vite now uses a custom base path
72+ assets . js . push ( `/.vite/ @vite/client` ) // Vite HMR client with custom base
73+ // Request the actual file path relative to the project root with the custom base
74+ assets . js . push ( `/.vite/ public/js/${ entryName } .js` )
7575 }
7676
7777 return assets
Original file line number Diff line number Diff line change 33
44import Prism from 'prismjs'
55import hljs from 'highlight.js'
6- import * as PDFObject from 'pdfobject'
6+ import PDFObject from 'pdfobject'
77import { saveAs } from 'file-saver'
88
99import escapeHTML from 'lodash/escape'
Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ import '@hackmd/ot/lib/undo-manager'
102102// import '@hackmd/ot/lib/client'
103103import '@hackmd/ot/lib/editor-client'
104104
105- import * as mousewhell from 'jquery-mousewheel'
105+ import mousewhell from 'jquery-mousewheel'
106106import '@vendor/jquery-textcomplete/jquery.textcomplete'
107107import '@vendor/jquery-ui/jquery-ui.min.js'
108108import '@vendor/bootstrap/tooltip.min.js'
Original file line number Diff line number Diff line change @@ -70,8 +70,8 @@ import debounce from 'lodash/debounce'
7070
7171import * as utils from './utils'
7272import config from './config'
73- import statusBarTemplate from './statusbar.html'
74- import toolBarTemplate from './toolbar.html'
73+ import statusBarTemplate from './statusbar.html?raw '
74+ import toolBarTemplate from './toolbar.html?raw '
7575import { linterOptions } from './markdown-lint'
7676import CodeMirrorSpellChecker , { supportLanguages , supportLanguageCodes } from './spellcheck'
7777import { initTableEditor } from './table-editor'
Original file line number Diff line number Diff line change 3333<!-- < %- include (' ../build/index-pack-scripts' ) % > -->
3434< % } %>
3535
36+ <script src =" <%- serverURL %>/config" ></script >
3637<% - generateTags (viteAssets (' index' )).jsTags %>
Original file line number Diff line number Diff line change 1212< % # Old webpack includes removed % >
1313< % } %>
1414<% # Inject Vite JS assets for the ' index' entry point %>
15+ <script src =" <%- serverURL %>/config" ></script >
1516<% - generateTags (viteAssets (' cover' )).jsTags %>
Original file line number Diff line number Diff line change 114114< % # Old webpack includes removed % >
115115< % } %>
116116<% # Inject Vite JS assets for the ' pretty' entry point %>
117+ <script src =" <%- serverURL %>/config" ></script >
117118<% - generateTags (viteAssets (' pretty' )).jsTags %>
118119<% - include (' shared/ga' ) %>
Original file line number Diff line number Diff line change 125125 < % # Old webpack includes removed % >
126126 < % } %>
127127 <% # Inject Vite JS assets for the ' slide' entry point %>
128+ <script src =" <%- serverURL %>/config" ></script >
128129 <% - generateTags (viteAssets (' slide' )).jsTags %>
129130 </body >
130131</html >
Original file line number Diff line number Diff line change @@ -25,9 +25,9 @@ export default defineConfig({
2525 // Add exclude for HTML files to prevent inject plugin from processing them
2626 exclude : [ '**/*.html' , '**/*.css' ]
2727 } ) ,
28- string ( {
29- include : '**/*.html'
30- } ) ,
28+ // string({
29+ // include: '**/*.html'
30+ // }),
3131 copy ( {
3232 targets : [
3333 {
@@ -143,7 +143,7 @@ export default defineConfig({
143143 ot : { } // Define ot as empty object for browser compatibility
144144 } ,
145145 root : __dirname ,
146- base : '/' ,
146+ base : '/.vite/' , // Updated to match our custom base path in app.js
147147 publicDir : false , // Let Vite handle all assets through middleware
148148 appType : 'custom' ,
149149 optimizeDeps : {
@@ -166,14 +166,15 @@ export default defineConfig({
166166 ws : true ,
167167 hmr : {
168168 protocol : 'ws' ,
169- host : 'localhost'
169+ host : 'localhost' ,
170+ path : '/.vite/hmr' // Specify a custom HMR path
170171 } ,
171172 fs : {
173+ strict : true , // Only serve explicitly allowed files
172174 allow : [
173175 path . resolve ( __dirname ) ,
174176 path . resolve ( __dirname , 'node_modules' )
175- ] ,
176- strict : false
177+ ]
177178 }
178179 }
179180} )
You can’t perform that action at this time.
0 commit comments