@@ -61,6 +61,71 @@ export function adex({
61
61
'virtual:adex:handler' ,
62
62
readFileSync ( join ( __dirname , '../runtime/handler.js' ) , 'utf8' )
63
63
) ,
64
+ createVirtualModule (
65
+ 'virtual:adex:server' ,
66
+ `import { createServer } from '${ adapterMap [ adapter ] } '
67
+ import { dirname, join } from 'node:path'
68
+ import { fileURLToPath } from 'node:url'
69
+ import { existsSync, readFileSync } from 'node:fs'
70
+ import { env } from 'adex/env'
71
+
72
+ import 'virtual:adex:font.css'
73
+ import 'virtual:adex:global.css'
74
+
75
+ const __dirname = dirname(fileURLToPath(import.meta.url))
76
+
77
+ const PORT = parseInt(env.get('PORT', '3000'), 10)
78
+ const HOST = env.get('HOST', 'localhost')
79
+
80
+ const paths = {
81
+ assets: join(__dirname, './assets'),
82
+ islands: join(__dirname, './islands'),
83
+ client: join(__dirname, '../client'),
84
+ }
85
+
86
+ function getServerManifest() {
87
+ const manifestPath = join(__dirname, 'manifest.json')
88
+ if (existsSync(manifestPath)) {
89
+ const manifestFile = readFileSync(manifestPath, 'utf8')
90
+ return parseManifest(manifestFile)
91
+ }
92
+ return {}
93
+ }
94
+
95
+ function getClientManifest() {
96
+ const manifestPath = join(__dirname, '../client/manifest.json')
97
+ if (existsSync(manifestPath)) {
98
+ const manifestFile = readFileSync(manifestPath, 'utf8')
99
+ return parseManifest(manifestFile)
100
+ }
101
+ return {}
102
+ }
103
+
104
+ function parseManifest(manifestString) {
105
+ try {
106
+ const manifestJSON = JSON.parse(manifestString)
107
+ return manifestJSON
108
+ } catch (err) {
109
+ return {}
110
+ }
111
+ }
112
+
113
+ const server = createServer({
114
+ port: PORT,
115
+ host: HOST,
116
+ adex:{
117
+ manifests:{server:getServerManifest(),client:getClientManifest()},
118
+ paths,
119
+ }
120
+ })
121
+
122
+ if ('run' in server) {
123
+ server.run()
124
+ }
125
+
126
+ export default server.fetch
127
+ `
128
+ ) ,
64
129
addFontsPlugin ( fonts ) ,
65
130
adexDevServer ( { islands } ) ,
66
131
adexBuildPrep ( { islands } ) ,
@@ -655,7 +720,7 @@ function adexGuards() {
655
720
656
721
// ignore usage of `process.env` in `adex/env`
657
722
const envLoadId = await this . resolve ( 'adex/env' )
658
- if ( id === envLoadId . id ) return
723
+ if ( id === envLoadId ? .id ) return
659
724
660
725
if ( code . includes ( 'process.env' ) ) {
661
726
this . error (
0 commit comments