server.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * @Description:
  3. * @Version: 1.668
  4. * @Autor: 地虎降天龙
  5. * @Date: 2026-01-14 09:40:09
  6. * @LastEditors: 地虎降天龙
  7. * @LastEditTime: 2026-03-25 10:20:41
  8. */
  9. import express from 'express'
  10. import { createServer } from 'node:http'
  11. // import { join } from 'node:path'
  12. import path from 'node:path'
  13. const app = express()
  14. const distPath = path.resolve('dist')
  15. const remoteEntryPath = path.join('assets', 'remoteEntry.js')
  16. app.use((req, res, next) => {
  17. res.setHeader('Access-Control-Allow-Origin', '*')
  18. next()
  19. })
  20. app.use(express.static(distPath, {
  21. setHeaders: (res, filePath) => {
  22. const normalizedFilePath = path.normalize(filePath)
  23. if (normalizedFilePath.endsWith(remoteEntryPath)) {
  24. res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate')
  25. res.setHeader('Pragma', 'no-cache')
  26. res.setHeader('Expires', '0')
  27. }
  28. },
  29. }))
  30. const server = createServer(app)
  31. server.listen(5000, 'localhost', () => {
  32. // eslint-disable-next-line no-console
  33. console.log('✅ remote running at http://localhost:5000')
  34. })