Replace nginx with Node.js static server for Easypanel
Some checks failed
Deploy to Easypanel / deploy (push) Has been cancelled
Some checks failed
Deploy to Easypanel / deploy (push) Has been cancelled
This commit is contained in:
@@ -9,3 +9,8 @@
|
||||
{"t":0,"agent":"a9b8a44","agent_type":"unknown","event":"agent_stop","success":true}
|
||||
{"t":0,"agent":"ad24c6c","agent_type":"unknown","event":"agent_stop","success":true}
|
||||
{"t":0,"agent":"a869894","agent_type":"unknown","event":"agent_stop","success":true}
|
||||
{"t":0,"agent":"a2a51be","agent_type":"unknown","event":"agent_stop","success":true}
|
||||
{"t":0,"agent":"a462672","agent_type":"unknown","event":"agent_stop","success":true}
|
||||
{"t":0,"agent":"a6bd471","agent_type":"unknown","event":"agent_stop","success":true}
|
||||
{"t":0,"agent":"aa941d3","agent_type":"unknown","event":"agent_stop","success":true}
|
||||
{"t":0,"agent":"a4954dc","agent_type":"unknown","event":"agent_stop","success":true}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"tool_name": "WebFetch",
|
||||
"tool_input_preview": "{\"url\":\"https://tina.io/docs/reference/config/\",\"prompt\":\"What is the correct media configuration for tinacms 2.x? The error is \\\"Cannot read properties of undefined (reading 'publicFolder')\\\". What s...",
|
||||
"tool_input_preview": "{\"url\":\"https://docs.astro.build/en/guides/deploy/easypanel/\",\"prompt\":\"How to deploy Astro to Easypanel? What type of service should be used? What port or configuration is needed for Easypanel + Astr...",
|
||||
"error": "timeout of 60000ms exceeded",
|
||||
"timestamp": "2026-04-27T12:46:34.409Z",
|
||||
"timestamp": "2026-04-28T00:25:40.810Z",
|
||||
"retry_count": 1
|
||||
}
|
||||
@@ -3,5 +3,5 @@
|
||||
"total_spawned": 0,
|
||||
"total_completed": 0,
|
||||
"total_failed": 0,
|
||||
"last_updated": "2026-04-27T13:57:02.103Z"
|
||||
"last_updated": "2026-04-28T00:28:25.963Z"
|
||||
}
|
||||
16
Dockerfile
16
Dockerfile
@@ -1,4 +1,3 @@
|
||||
# Build stage
|
||||
FROM node:22-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
@@ -8,17 +7,16 @@ RUN npm install
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
# Static files stage
|
||||
FROM nginx:alpine AS runner
|
||||
FROM node:22-alpine AS runner
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy static files from builder
|
||||
ENV PORT=8080
|
||||
ENV DIST_DIR=./dist
|
||||
|
||||
COPY --from=builder /app/dist ./dist
|
||||
COPY --from=builder /app/server.js .
|
||||
|
||||
# Copy nginx config
|
||||
COPY nginx.conf /etc/nginx/http.d/default.conf
|
||||
EXPOSE 8080
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
CMD ["node", "server.js"]
|
||||
@@ -9,7 +9,8 @@
|
||||
"dev:tina": "tinacms dev --port 3001",
|
||||
"build": "astro build",
|
||||
"preview": "astro preview",
|
||||
"astro": "astro"
|
||||
"astro": "astro",
|
||||
"start": "node server.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@astrojs/check": "^0.9.4",
|
||||
|
||||
74
server.js
Normal file
74
server.js
Normal file
@@ -0,0 +1,74 @@
|
||||
import { createServer } from 'node:http'
|
||||
import { readFile } from 'node:fs/promises'
|
||||
import { join, extname } from 'node:path'
|
||||
import { existsSync } from 'node:fs'
|
||||
|
||||
const PORT = process.env.PORT || 8080
|
||||
const DIST_DIR = process.env.DIST_DIR || './dist'
|
||||
|
||||
const mimeTypes = {
|
||||
'.html': 'text/html',
|
||||
'.js': 'application/javascript',
|
||||
'.css': 'text/css',
|
||||
'.json': 'application/json',
|
||||
'.png': 'image/png',
|
||||
'.jpg': 'image/jpeg',
|
||||
'.svg': 'image/svg+xml',
|
||||
'.ico': 'image/x-icon',
|
||||
'.woff': 'font/woff',
|
||||
'.woff2': 'font/woff2',
|
||||
}
|
||||
|
||||
async function serveFile(res, filePath) {
|
||||
try {
|
||||
const content = await readFile(filePath)
|
||||
const ext = extname(filePath)
|
||||
const contentType = mimeTypes[ext] || 'application/octet-stream'
|
||||
res.writeHead(200, { 'Content-Type': contentType })
|
||||
res.end(content)
|
||||
} catch {
|
||||
res.writeHead(404)
|
||||
res.end('Not found')
|
||||
}
|
||||
}
|
||||
|
||||
const server = createServer(async (req, res) => {
|
||||
let url = req.url.split('?')[0]
|
||||
|
||||
// Try exact file first
|
||||
let filePath = join(DIST_DIR, url)
|
||||
if (existsSync(filePath) && !existsSync(join(DIST_DIR, url, 'index.html'))) {
|
||||
await serveFile(res, filePath)
|
||||
return
|
||||
}
|
||||
|
||||
// Try directory index
|
||||
const indexPaths = [
|
||||
join(DIST_DIR, url, 'index.html'),
|
||||
join(DIST_DIR, 'index.html'),
|
||||
]
|
||||
for (const idx of indexPaths) {
|
||||
if (existsSync(idx)) {
|
||||
await serveFile(res, idx)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Try with .html extension
|
||||
if (!extname(url)) {
|
||||
const htmlPath = join(DIST_DIR, url + '.html')
|
||||
if (existsSync(htmlPath)) {
|
||||
await serveFile(res, htmlPath)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 404
|
||||
res.writeHead(404)
|
||||
res.end('Not found')
|
||||
})
|
||||
|
||||
server.listen(PORT, '0.0.0.0', () => {
|
||||
console.log(`Server running at http://0.0.0.0:${PORT}`)
|
||||
console.log(`Serving files from ${DIST_DIR}`)
|
||||
})
|
||||
Reference in New Issue
Block a user