mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 07:40:43 +00:00
have nginx cache static assets
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
build/
|
||||
node_modules/
|
||||
out/
|
||||
static/
|
||||
TODO.txt
|
||||
resources/images/.DS_Store
|
||||
resources/.DS_Store
|
||||
|
||||
+27
@@ -30,6 +30,9 @@ map $uri $uri_path {
|
||||
default $uri;
|
||||
}
|
||||
|
||||
# Cache configuration
|
||||
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=1g;
|
||||
|
||||
server {
|
||||
listen 80 default_server;
|
||||
|
||||
@@ -37,6 +40,30 @@ server {
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log;
|
||||
|
||||
# Static file caching for the "static" directory
|
||||
location ~ ^/static/(.*)$ {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_cache STATIC;
|
||||
proxy_ignore_headers Cache-Control;
|
||||
proxy_cache_valid 200 302 60m;
|
||||
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
|
||||
proxy_cache_lock on;
|
||||
add_header X-Cache-Status $upstream_cache_status;
|
||||
|
||||
# Cache bypass if needed (for development/debugging)
|
||||
proxy_cache_bypass $http_pragma $http_authorization;
|
||||
|
||||
# No TTL as requested (browser will check each time)
|
||||
expires -1;
|
||||
add_header Cache-Control "no-cache";
|
||||
|
||||
# Standard proxy headers
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Main location
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
|
||||
+9
-7
@@ -14,8 +14,8 @@ export default (env, argv) => {
|
||||
entry: "./src/client/Main.ts",
|
||||
output: {
|
||||
publicPath: "/",
|
||||
filename: "bundle.js",
|
||||
path: path.resolve(__dirname, "out"),
|
||||
filename: "static/js/bundle.js",
|
||||
path: path.resolve(__dirname, "static"),
|
||||
clean: true,
|
||||
},
|
||||
module: {
|
||||
@@ -57,7 +57,7 @@ export default (env, argv) => {
|
||||
test: /\.(png|jpe?g|gif)$/i,
|
||||
type: "asset/resource",
|
||||
generator: {
|
||||
filename: "images/[hash][ext][query]",
|
||||
filename: "static/images/[name]-[hash:8][ext]",
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -75,8 +75,8 @@ export default (env, argv) => {
|
||||
loader: "file-loader",
|
||||
options: {
|
||||
name: "[name].[ext]",
|
||||
outputPath: "fonts/",
|
||||
publicPath: "../fonts/", // This is important
|
||||
outputPath: "static/fonts/",
|
||||
publicPath: "../fonts/",
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -106,7 +106,9 @@ export default (env, argv) => {
|
||||
"process.env.GAME_ENV": JSON.stringify(isProduction ? "prod" : "dev"),
|
||||
}),
|
||||
new CopyPlugin({
|
||||
patterns: [{ from: "resources", to: path.resolve(__dirname, "out") }],
|
||||
patterns: [
|
||||
{ from: "resources", to: path.resolve(__dirname, "static") },
|
||||
],
|
||||
options: {
|
||||
concurrency: 100,
|
||||
},
|
||||
@@ -117,7 +119,7 @@ export default (env, argv) => {
|
||||
: {
|
||||
devMiddleware: { writeToDisk: true },
|
||||
static: {
|
||||
directory: path.join(__dirname, "out"),
|
||||
directory: path.join(__dirname, "static"),
|
||||
},
|
||||
historyApiFallback: true,
|
||||
compress: true,
|
||||
|
||||
Reference in New Issue
Block a user