Spaces:
Sleeping
Sleeping
itseffi commited on
Commit ·
3f0ac03
1
Parent(s): 4d94411
v0
Browse files- Dockerfile +5 -9
- next.config.ts +0 -1
- package.json +1 -0
- server.js +29 -0
Dockerfile
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
-
# Dockerfile for Next.js on HuggingFace Spaces (
|
| 2 |
|
| 3 |
FROM node:20 AS base
|
| 4 |
|
| 5 |
-
# Install dependencies only when needed
|
| 6 |
FROM base AS deps
|
| 7 |
WORKDIR /app
|
| 8 |
COPY package.json package-lock.json* ./
|
|
@@ -23,14 +22,11 @@ ENV NODE_ENV=production
|
|
| 23 |
ENV PORT=3000
|
| 24 |
ENV HOSTNAME=0.0.0.0
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
COPY --from=builder /app/public ./public
|
| 30 |
-
COPY --from=builder
|
| 31 |
-
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
| 32 |
-
|
| 33 |
-
USER nextjs
|
| 34 |
|
| 35 |
EXPOSE 3000
|
| 36 |
|
|
|
|
| 1 |
+
# Dockerfile for Next.js on HuggingFace Spaces (custom server)
|
| 2 |
|
| 3 |
FROM node:20 AS base
|
| 4 |
|
|
|
|
| 5 |
FROM base AS deps
|
| 6 |
WORKDIR /app
|
| 7 |
COPY package.json package-lock.json* ./
|
|
|
|
| 22 |
ENV PORT=3000
|
| 23 |
ENV HOSTNAME=0.0.0.0
|
| 24 |
|
| 25 |
+
COPY --from=builder /app/package.json ./
|
| 26 |
+
COPY --from=builder /app/node_modules ./node_modules
|
| 27 |
+
COPY --from=builder /app/.next ./.next
|
| 28 |
COPY --from=builder /app/public ./public
|
| 29 |
+
COPY --from=builder /app/server.js ./server.js
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
EXPOSE 3000
|
| 32 |
|
next.config.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import type { NextConfig } from "next";
|
| 2 |
|
| 3 |
const nextConfig: NextConfig = {
|
| 4 |
-
output: "standalone",
|
| 5 |
images: {
|
| 6 |
unoptimized: true,
|
| 7 |
},
|
|
|
|
| 1 |
import type { NextConfig } from "next";
|
| 2 |
|
| 3 |
const nextConfig: NextConfig = {
|
|
|
|
| 4 |
images: {
|
| 5 |
unoptimized: true,
|
| 6 |
},
|
package.json
CHANGED
|
@@ -21,6 +21,7 @@
|
|
| 21 |
"@radix-ui/react-tooltip": "^1.2.8",
|
| 22 |
"class-variance-authority": "^0.7.1",
|
| 23 |
"clsx": "^2.1.1",
|
|
|
|
| 24 |
"lucide-react": "^0.563.0",
|
| 25 |
"next": "16.1.6",
|
| 26 |
"next-themes": "^0.4.6",
|
|
|
|
| 21 |
"@radix-ui/react-tooltip": "^1.2.8",
|
| 22 |
"class-variance-authority": "^0.7.1",
|
| 23 |
"clsx": "^2.1.1",
|
| 24 |
+
"express": "^4.21.2",
|
| 25 |
"lucide-react": "^0.563.0",
|
| 26 |
"next": "16.1.6",
|
| 27 |
"next-themes": "^0.4.6",
|
server.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const path = require("path");
|
| 2 |
+
const express = require("express");
|
| 3 |
+
const next = require("next");
|
| 4 |
+
|
| 5 |
+
const port = parseInt(process.env.PORT || "3000", 10);
|
| 6 |
+
const hostname = process.env.HOSTNAME || "0.0.0.0";
|
| 7 |
+
|
| 8 |
+
const app = next({ dev: false, hostname, port });
|
| 9 |
+
const handle = app.getRequestHandler();
|
| 10 |
+
|
| 11 |
+
app
|
| 12 |
+
.prepare()
|
| 13 |
+
.then(() => {
|
| 14 |
+
const server = express();
|
| 15 |
+
|
| 16 |
+
// Serve Next.js build assets and public files explicitly.
|
| 17 |
+
server.use("/_next/static", express.static(path.join(__dirname, ".next", "static")));
|
| 18 |
+
server.use(express.static(path.join(__dirname, "public")));
|
| 19 |
+
|
| 20 |
+
server.all("*", (req, res) => handle(req, res));
|
| 21 |
+
|
| 22 |
+
server.listen(port, hostname, () => {
|
| 23 |
+
console.log(`Server listening on http://${hostname}:${port}`);
|
| 24 |
+
});
|
| 25 |
+
})
|
| 26 |
+
.catch((err) => {
|
| 27 |
+
console.error("Failed to start server", err);
|
| 28 |
+
process.exit(1);
|
| 29 |
+
});
|