-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use an express entry point server.js to enable rate limiting middleware
- Loading branch information
Chris Hatch
committed
Mar 29, 2024
1 parent
ad39dd1
commit 4a3fb10
Showing
3 changed files
with
80 additions
and
25 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,7 +1,7 @@ | ||
{ | ||
"name": "stellarexplorer", | ||
"description": "Ledger explorer for the Stellar network", | ||
"version": "2.6.0-beta", | ||
"version": "2.6.1", | ||
"license": "Apache-2.0", | ||
"author": "Chris Hatch <[email protected]>", | ||
"homepage": "https://steexp.com", | ||
|
@@ -25,9 +25,9 @@ | |
"sideEffects": false, | ||
"scripts": { | ||
"build": "remix build", | ||
"start": "remix-serve ./build/index.js", | ||
"start": "node server.js", | ||
"deploy": "fly deploy --remote-only", | ||
"dev": "remix dev", | ||
"dev": "nodemon server.js", | ||
"jest-preview": "jest-preview", | ||
"typecheck": "tsc", | ||
"lint": "eslint --ignore-path .gitignore '**/*.{js,jsx,ts,tsx}'", | ||
|
@@ -109,4 +109,4 @@ | |
"lint-staged": { | ||
"*.{js,jsx,ts,tsx}": "eslint --ignore-path .gitignore" | ||
} | ||
} | ||
} |
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,45 @@ | ||
|
||
const express = require('express') | ||
const { rateLimit } = require('express-rate-limit') | ||
const { createRequestHandler } = require('@remix-run/express') | ||
const serverBuild = require('./build/index') | ||
|
||
const app = express() | ||
|
||
// app.use(compression()); | ||
|
||
// limit the bots that are hitting this at a fast rate | ||
const limiter = rateLimit({ | ||
windowMs: 8 * 1000, | ||
limit: 5, | ||
standardHeaders: 'draft-7', | ||
legacyHeaders: false, | ||
}) | ||
app.use('/account/*', limiter); | ||
|
||
app.use((req, res, next) => { | ||
const ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress; | ||
console.log(`request ip: ${ip}`); | ||
next(); | ||
}); | ||
|
||
app.use(express.static("public")); | ||
|
||
|
||
// ... set up any middleware, like rateLimit, here | ||
|
||
app.all( | ||
'*', | ||
createRequestHandler({ | ||
build: serverBuild, | ||
getLoadContext() { | ||
// Your context here | ||
}, | ||
}) | ||
) | ||
|
||
const port = process.env.PORT ?? 3000 | ||
|
||
app.listen(port, () => { | ||
console.log(`Express server listening on port ${port}`) | ||
}) |
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,23 +1,33 @@ | ||
{ | ||
"include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"], | ||
"compilerOptions": { | ||
"lib": ["DOM", "DOM.Iterable", "ES2019"], | ||
"isolatedModules": true, | ||
"esModuleInterop": true, | ||
"jsx": "react-jsx", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"target": "ES2019", | ||
"strict": true, | ||
"allowJs": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"baseUrl": ".", | ||
"paths": { | ||
"~/*": ["./app/*"] | ||
"include": [ | ||
"remix.env.d.ts", | ||
"**/*.ts", | ||
"**/*.tsx", | ||
"app/server.js" | ||
], | ||
"compilerOptions": { | ||
"lib": [ | ||
"DOM", | ||
"DOM.Iterable", | ||
"ES2019" | ||
], | ||
"isolatedModules": true, | ||
"esModuleInterop": true, | ||
"jsx": "react-jsx", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"target": "ES2019", | ||
"strict": true, | ||
"allowJs": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"baseUrl": ".", | ||
"paths": { | ||
"~/*": [ | ||
"./app/*" | ||
] | ||
}, | ||
// Remix takes care of building everything in `remix build`. | ||
"noEmit": true, | ||
"module": "commonjs", // NOTE: added to support dynamic import of p-retry (see: https://www.typescriptlang.org/ja/tsconfig#module) | ||
}, | ||
|
||
// Remix takes care of building everything in `remix build`. | ||
"noEmit": true, | ||
"module": "commonjs", // NOTE: added to support dynamic import of p-retry (see: https://www.typescriptlang.org/ja/tsconfig#module) | ||
}, | ||
} | ||
} |