Skip to content

Commit bcf28de

Browse files
committed
Move to server.js
1 parent b6ff459 commit bcf28de

File tree

3 files changed

+63
-25
lines changed

3 files changed

+63
-25
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"dev": "vite",
77
"build": "vite build",
88
"preview": "vite preview",
9-
"start": "npx serve -s dist -l 0.0.0.0:$PORT"
9+
"start": "node server.js"
1010
},
1111
"dependencies": {
1212
"@emotion/react": "^11.14.0",
@@ -17,12 +17,13 @@
1717
"@fortawesome/free-solid-svg-icons": "^6.7.2",
1818
"@fortawesome/react-fontawesome": "^0.2.2",
1919
"@mui/material": "^7.1.1",
20+
"compression": "^1.7.4",
21+
"express": "^4.18.2",
2022
"i18next": "^25.2.1",
2123
"react": "^19.1.0",
2224
"react-dom": "^19.1.0",
2325
"react-i18next": "^15.5.3",
24-
"react-router-dom": "^7.1.1",
25-
"serve": "^14.2.4"
26+
"react-router-dom": "^7.1.1"
2627
},
2728
"devDependencies": {
2829
"@eslint/js": "^9.17.0",

server.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const express = require('express');
2+
const path = require('path');
3+
const compression = require('compression');
4+
5+
const app = express();
6+
const port = process.env.PORT || 3000;
7+
8+
// Enable gzip compression
9+
app.use(compression());
10+
11+
// Serve static files from the current directory (dist in production)
12+
app.use(express.static(path.join(__dirname), {
13+
maxAge: '1y', // Cache static assets for 1 year
14+
etag: false
15+
}));
16+
17+
// Set security headers
18+
app.use((req, res, next) => {
19+
res.setHeader('X-Content-Type-Options', 'nosniff');
20+
res.setHeader('X-Frame-Options', 'DENY');
21+
res.setHeader('X-XSS-Protection', '1; mode=block');
22+
next();
23+
});
24+
25+
// Handle client-side routing - serve index.html for all non-file routes
26+
app.get('*', (req, res) => {
27+
// Only serve index.html for routes that don't have file extensions
28+
if (!req.path.includes('.')) {
29+
res.sendFile(path.join(__dirname, 'index.html'));
30+
} else {
31+
res.status(404).send('File not found');
32+
}
33+
});
34+
35+
app.listen(port, () => {
36+
console.log(`Server running on port ${port}`);
37+
});

web.config

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<system.webServer>
4+
<webSocket enabled="false" />
5+
<handlers>
6+
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
7+
</handlers>
48
<rewrite>
59
<rules>
6-
<rule name="Handle History API">
7-
<match url=".*" />
8-
<conditions logicalGrouping="MatchAll">
9-
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
10-
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
10+
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
11+
<match url="^server.js\/debug[\/]?" />
12+
</rule>
13+
<rule name="StaticContent">
14+
<action type="Rewrite" url="public{REQUEST_URI}"/>
15+
</rule>
16+
<rule name="DynamicContent">
17+
<conditions>
18+
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
1119
</conditions>
12-
<action type="Rewrite" url="/index.html" />
20+
<action type="Rewrite" url="server.js"/>
1321
</rule>
1422
</rules>
1523
</rewrite>
16-
<staticContent>
17-
<mimeMap fileExtension=".js" mimeType="application/javascript" />
18-
<mimeMap fileExtension=".css" mimeType="text/css" />
19-
<mimeMap fileExtension=".json" mimeType="application/json" />
20-
<mimeMap fileExtension=".woff" mimeType="font/woff" />
21-
<mimeMap fileExtension=".woff2" mimeType="font/woff2" />
22-
</staticContent>
23-
<httpCompression>
24-
<dynamicTypes>
25-
<add mimeType="application/javascript" enabled="true" />
26-
<add mimeType="text/css" enabled="true" />
27-
</dynamicTypes>
28-
</httpCompression>
24+
<security>
25+
<requestFiltering>
26+
<hiddenSegments>
27+
<remove segment="bin"/>
28+
</hiddenSegments>
29+
</requestFiltering>
30+
</security>
2931
<httpErrors existingResponse="PassThrough" />
32+
<iisnode watchedFiles="web.config;*.js"/>
3033
</system.webServer>
3134
</configuration>
32-
node_env="%node_env%"
33-
nodeProcessCountPerApplication="1"
34-
maxConcurrentRequestsPerProcess="1024"
3535
maxNamedPipeConnectionRetry="3"
3636
namedPipeConnectionRetryDelay="2000"
3737
asyncCompletionThreadCount="0"

0 commit comments

Comments
 (0)