-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update Dockerfile and add new server.js setup
- Loading branch information
Showing
4 changed files
with
180 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,47 @@ | ||
# Include any files or directories that you don't want to be copied to your | ||
# container here (e.g., local build artifacts, temporary files, etc.). | ||
# | ||
# For more help, visit the .dockerignore file reference guide at | ||
# https://docs.docker.com/go/build-context-dockerignore/ | ||
|
||
**/.classpath | ||
**/.dockerignore | ||
**/.env | ||
**/.git | ||
**/.gitignore | ||
**/.project | ||
**/.settings | ||
**/.toolstarget | ||
**/.vs | ||
**/.vscode | ||
**/.next | ||
**/.cache | ||
**/*.*proj.user | ||
**/*.dbmdl | ||
**/*.jfm | ||
**/charts | ||
**/docker-compose* | ||
**/compose* | ||
**/Dockerfile* | ||
**/node_modules | ||
**/npm-debug.log | ||
**/obj | ||
**/secrets.dev.yaml | ||
**/values.dev.yaml | ||
**/build | ||
**/dist | ||
LICENSE | ||
README.md | ||
# Version control | ||
.git | ||
.gitignore | ||
.github | ||
|
||
# Dependencies | ||
node_modules | ||
.pnpm-store | ||
|
||
# Build outputs | ||
build | ||
dist | ||
|
||
# Development files | ||
.env | ||
.env.* | ||
*.log | ||
npm-debug.log* | ||
.cache | ||
|
||
# IDE and editor files | ||
.vscode | ||
.idea | ||
*.swp | ||
*.swo | ||
|
||
# Test files | ||
__tests__ | ||
*.test.js | ||
*.spec.js | ||
coverage | ||
|
||
# Documentation | ||
docs | ||
*.md | ||
|
||
# Temporary files | ||
.DS_Store | ||
*.tmp | ||
*.temp | ||
|
||
# Allow specific files/folders | ||
!package.json | ||
!pnpm-lock.yaml | ||
!server.js | ||
!app/ | ||
!public/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.git | ||
.gitignore | ||
node_modules/ | ||
npm-debug.log | ||
README.md | ||
.env | ||
*.test.js | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { createRequestHandler } from "@remix-run/express"; | ||
import { installGlobals } from "@remix-run/node"; | ||
import compression from "compression"; | ||
import express from "express"; | ||
import { fileURLToPath } from "url"; | ||
import { dirname, join } from "path"; | ||
import fs from 'fs'; | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
||
installGlobals(); | ||
|
||
const viteDevServer = | ||
process.env.NODE_ENV === "production" | ||
? undefined | ||
: await import("vite").then((vite) => | ||
vite.createServer({ | ||
server: { middlewareMode: true }, | ||
}) | ||
); | ||
|
||
const app = express(); | ||
|
||
// Add health check endpoint | ||
app.get('/_health', (req, res) => { | ||
res.status(200).send('OK'); | ||
}); | ||
|
||
app.use(compression()); | ||
|
||
// http://expressjs.com/en/advanced/best-practice-security.html#at-a-minimum-disable-x-powered-by-header | ||
app.disable("x-powered-by"); | ||
|
||
// handle asset requests | ||
if (viteDevServer) { | ||
app.use(viteDevServer.middlewares); | ||
} else { | ||
app.use( | ||
"/assets", | ||
express.static(join(__dirname, "build/client/assets"), { immutable: true, maxAge: "1y" }) | ||
); | ||
} | ||
app.use(express.static(join(__dirname, "build/client"), { maxAge: "1h" })); | ||
|
||
// Log build directory contents for debugging | ||
console.log('Build directory contents:'); | ||
try { | ||
console.log('Client directory:', fs.readdirSync(join(__dirname, 'build/client'))); | ||
} catch (error) { | ||
console.error('Error reading build directory:', error); | ||
} | ||
|
||
// handle SSR requests | ||
app.all( | ||
"*", | ||
createRequestHandler({ | ||
build: viteDevServer | ||
? () => viteDevServer.ssrLoadModule("virtual:remix/server-build") | ||
: { default: { default: { handler: (req, res) => res.sendFile(join(__dirname, 'build/client/index.html')) } } }, | ||
}) | ||
); | ||
|
||
const port = process.env.PORT || 3000; | ||
const server = app.listen(port, () => { | ||
console.log(`Express server listening on port ${port}`); | ||
}); | ||
|
||
// Graceful shutdown | ||
process.on('SIGTERM', () => { | ||
console.log('SIGTERM signal received: closing HTTP server'); | ||
server.close(() => { | ||
console.log('HTTP server closed'); | ||
}); | ||
}); |