Skip to content

Commit

Permalink
Revert "feat(docker): configure environment variables for hostname an…
Browse files Browse the repository at this point in the history
…d port"

This reverts commit cac09ca
  • Loading branch information
kiritoko1029 committed Dec 23, 2024
1 parent 12d7424 commit 5be2a5f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ RUN apk update && apk add --no-cache git
ENV OPENAI_API_KEY=""
ENV GOOGLE_API_KEY=""
ENV CODE=""
ENV HOSTNAME="0.0.0.0"
ENV PORT="3000"

WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
Expand All @@ -36,8 +34,6 @@ ENV PROXY_URL=""
ENV OPENAI_API_KEY=""
ENV GOOGLE_API_KEY=""
ENV CODE=""
ENV HOSTNAME="0.0.0.0"
ENV PORT="3000"

COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
Expand All @@ -47,6 +43,7 @@ COPY --from=builder /app/.next/server ./.next/server
EXPOSE 3000

CMD if [ -n "$PROXY_URL" ]; then \
export HOSTNAME="0.0.0.0"; \
protocol=$(echo $PROXY_URL | cut -d: -f1); \
host=$(echo $PROXY_URL | cut -d/ -f3 | cut -d: -f1); \
port=$(echo $PROXY_URL | cut -d: -f3); \
Expand Down
28 changes: 4 additions & 24 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,15 @@ import next from 'next';
import { setupWebSocket } from './app/api/websocket';

const dev = process.env.NODE_ENV !== 'production';
const hostname = process.env.HOSTNAME || '0.0.0.0';
const port = parseInt(process.env.PORT || '3000', 10);
const hostname = 'localhost';
const port = 3000;

const app = next({ dev, hostname, port });
const handle = app.getRequestHandler();

app.prepare().then(() => {
const server = createServer(async (req, res) => {
try {
if (req.method === 'OPTIONS') {
res.writeHead(200, {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
'Access-Control-Max-Age': '86400'
});
res.end();
return;
}

if (req.headers.upgrade && req.headers.upgrade.toLowerCase() === 'websocket') {
res.writeHead(101, {
'Upgrade': 'websocket',
'Connection': 'Upgrade'
});
return;
}

const parsedUrl = parse(req.url!, true);
await handle(req, res, parsedUrl);
} catch (err) {
Expand All @@ -43,8 +24,7 @@ app.prepare().then(() => {

setupWebSocket(server);

server.listen(port, hostname, () => {
console.log(`> Server listening at http://${hostname}:${port}`);
console.log(`> WebSocket server is ready`);
server.listen(port, () => {
console.log(`> Ready on http://${hostname}:${port}`);
});
});

0 comments on commit 5be2a5f

Please sign in to comment.