@@ -3,9 +3,9 @@ import fs from 'node:fs';
3
3
import path from 'node:path' ;
4
4
import process from 'node:process' ;
5
5
import { pathToFileURL } from 'node:url' ;
6
- import express from 'express ' ;
6
+ import polka from 'polka ' ;
7
7
import compression from 'compression' ;
8
- import serveStatic from 'serve-static ' ;
8
+ import sirv from 'sirv ' ;
9
9
10
10
let port = 3000 ;
11
11
const args = process . argv . slice ( 2 ) ;
@@ -23,7 +23,7 @@ async function createServer(root = process.cwd(), isProd = process.env.NODE_ENV
23
23
? JSON . parse ( fs . readFileSync ( resolve ( 'dist/client/.vite/ssr-manifest.json' ) , 'utf-8' ) )
24
24
: { } ;
25
25
26
- const app = express ( ) ;
26
+ const app = polka ( ) ;
27
27
28
28
/**
29
29
* @type {import('vite').ViteDevServer }
@@ -52,8 +52,8 @@ async function createServer(root = process.cwd(), isProd = process.env.NODE_ENV
52
52
} else {
53
53
app . use ( compression ( ) ) ;
54
54
app . use (
55
- serveStatic ( resolve ( 'dist/client' ) , {
56
- index : false
55
+ sirv ( resolve ( 'dist/client' ) , {
56
+ extensions : [ ]
57
57
} )
58
58
) ;
59
59
}
@@ -79,29 +79,31 @@ async function createServer(root = process.cwd(), isProd = process.env.NODE_ENV
79
79
const html = template
80
80
. replace ( '<!--head-outlet-->' , headElements )
81
81
. replace ( '<!--app-outlet-->' , appHtml ) ;
82
-
83
- res . status ( 200 ) . set ( { 'Content-Type' : 'text/html' } ) . end ( html ) ;
82
+ res . writeHead ( 200 , { 'Content-Type' : 'text/html' } ) . end ( html ) ;
84
83
} catch ( e ) {
85
84
if ( vite ) vite . ssrFixStacktrace ( e ) ;
86
85
console . log ( e . stack ) ;
87
- res . status ( 500 ) . end ( e . stack ) ;
86
+ res . writeHead ( 500 , { 'Content-Type' : 'text/plain' } ) . end ( e . stack ) ;
88
87
}
89
88
} ) ;
90
89
91
90
return { app, vite } ;
92
91
}
93
92
94
93
createServer ( ) . then ( ( { app } ) => {
95
- const server = app . listen ( port , ( ) => {
94
+ app . listen ( port , ( ) => {
96
95
console . log ( 'http://localhost:' + port ) ;
97
96
} ) ;
98
97
const exitProcess = async ( ) => {
99
98
process . off ( 'SIGTERM' , exitProcess ) ;
100
99
process . off ( 'SIGINT' , exitProcess ) ;
101
100
process . stdin . off ( 'end' , exitProcess ) ;
102
101
try {
103
- await server . close ( ( ) => {
104
- console . log ( 'ssr server closed' ) ;
102
+ await new Promise ( ( resolve ) => {
103
+ app . server . close ( ( ) => {
104
+ console . log ( 'ssr server closed' ) ;
105
+ resolve ( ) ;
106
+ } ) ;
105
107
} ) ;
106
108
} finally {
107
109
// eslint-disable-next-line n/no-process-exit
0 commit comments