-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathserve.js
More file actions
41 lines (36 loc) · 1.13 KB
/
serve.js
File metadata and controls
41 lines (36 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const express = require('express')
const path = require('path')
const http = require('http')
const app = express()
const PORT = 8080
const SKILLS_HOST = '127.0.0.1'
const SKILLS_PORT = 9005
// Proxy /api/skills → ethskills server
app.get('/api/skills', (req, res) => {
const options = {
hostname: SKILLS_HOST,
port: SKILLS_PORT,
path: '/skills',
method: 'GET',
}
const proxy = http.request(options, (proxyRes) => {
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Content-Type', 'application/json')
res.statusCode = proxyRes.statusCode
proxyRes.pipe(res)
})
proxy.on('error', (err) => {
res.status(502).json({ error: 'Skills server unavailable', detail: err.message })
})
proxy.end()
})
// Serve static Remix IDE files
app.use(express.static(path.join(__dirname, 'dist/apps/remix-ide')))
// SPA fallback
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/apps/remix-ide', 'index.html'))
})
app.listen(PORT, '0.0.0.0', () => {
console.log(`Remix IDE running on http://0.0.0.0:${PORT}`)
console.log(`Skills API proxied at http://0.0.0.0:${PORT}/api/skills`)
})