()
| 6 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 7 | |
| 8 | async function createServer() { |
| 9 | const app = express(); |
| 10 | const resolve = (p) => path.resolve(__dirname, p); |
| 11 | |
| 12 | // @ts-ignore |
| 13 | app.use((await import('compression')).default()); |
| 14 | |
| 15 | app.use( |
| 16 | // @ts-ignore |
| 17 | (await import('serve-static')).default( |
| 18 | resolve('dist/apps/analog-app/client'), |
| 19 | { |
| 20 | index: false, |
| 21 | }, |
| 22 | ), |
| 23 | ); |
| 24 | |
| 25 | app.use( |
| 26 | '/api', |
| 27 | (await import(resolve('dist/apps/analog-app/server/server/index.mjs'))) |
| 28 | .listener, |
| 29 | ); |
| 30 | |
| 31 | app.use('*', async (req, res, next) => { |
| 32 | const url = req.originalUrl; |
| 33 | |
| 34 | try { |
| 35 | const template = fs.readFileSync( |
| 36 | path.resolve(__dirname, 'dist/apps/analog-app/client/index.html'), |
| 37 | 'utf-8', |
| 38 | ); |
| 39 | |
| 40 | const render = ( |
| 41 | await import(`${__dirname}/dist/apps/analog-app/ssr/main.server.mjs`) |
| 42 | )['default']; |
| 43 | |
| 44 | const html = await render(url, template); |
| 45 | |
| 46 | res.status(200).set({ 'Content-Type': 'text/html' }).end(html); |
| 47 | } catch (e) { |
| 48 | res.end('Error'); |
| 49 | // console.error(e); |
| 50 | } |
| 51 | }); |
| 52 | |
| 53 | app.listen(3000, () => { |
| 54 | console.log('http://localhost:3000'); |
| 55 | }); |
| 56 | } |
| 57 | |
| 58 | createServer(); |
no test coverage detected