Comments (2)
how did you integrate with remix? im using the grunge stack, do we just use
from remix.
This is my entry.client.tsx
config:
export function initSentry() {
init({
enabled: window.ENV.NODE_ENV === "production",
dsn: window.ENV.SENTRY_DSN,
environment: window.ENV.NODE_ENV,
beforeSend(event) {
if (event.request?.url) {
const url = new URL(event.request.url)
if (
url.protocol === "chrome-extension:" ||
url.protocol === "moz-extension:"
) {
// This error is from a browser extension, ignore it
return null
}
}
return event
},
integrations: [
browserTracingIntegration({
useEffect,
useLocation,
useMatches,
}),
// Replay is only available in the client
replayIntegration(),
browserProfilingIntegration(),
],
tracesSampleRate: 1,
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
profilesSampleRate: 1,
})
}
This is my entry.server.tsx
config:
export function initSentry() {
init({
enabled: env.NODE_ENV === "production",
dsn: env.SENTRY_DSN,
environment: env.NODE_ENV,
tracesSampleRate: 1,
profilesSampleRate: 1,
integrations: [
new Integrations.Http({ tracing: true }),
nodeProfilingIntegration(),
],
tracesSampler(samplingContext) {
// ignore healthcheck transactions by other services (consul, etc.)
if (samplingContext.request?.url?.includes("/resources/healthcheck")) {
return 0
}
return 1
},
profilesSampler(samplingContext) {
// ignore healthcheck transactions by other services (consul, etc.)
if (samplingContext.request?.url?.includes("/resources/healthcheck")) {
return 0
}
return 1
},
beforeSendTransaction(event) {
// ignore all healthcheck related transactions
// note that name of header here is case-sensitive
if (event.request?.headers?.["x-healthcheck"] === "true") {
return null
}
return event
},
})
}
And this is my express config:
installGlobals()
const createRequestHandler =
env.NODE_ENV === "production"
? wrapExpressCreateRequestHandler(_createRequestHandler)
: _createRequestHandler
const viteDevServer =
env.NODE_ENV === "production"
? undefined
: await import("vite").then((vite) =>
vite.createServer({
server: { middlewareMode: true },
}),
)
const app = express()
// Fly.io requires the app to trust the proxy
app.set("trust proxy", true)
app.use(requireHttps)
app.get("*", removeTrailingSlash)
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")
app.use(Sentry.Handlers.requestHandler())
app.use(Sentry.Handlers.tracingHandler())
if (viteDevServer) {
app.use(viteDevServer.middlewares)
} else {
// Remix fingerprints its assets so we can cache forever.
app.use(
"/assets",
express.static("build/client/assets", { immutable: true, maxAge: "1y" }),
)
// Everything else (like favicon.ico) is cached for an hour. You may want to be
// more aggressive with this caching.
app.use(express.static("build/client", { maxAge: "1h" }))
}
app.get(["/img/*", "/favicons/*"], (_req, res) => {
// if we made it past the express.static for these, then we're missing something.
// So we'll just send a 404 and won't bother calling other middleware.
return res.status(404).send("Not found")
})
app.use(logger)
app.use(helmet())
app.use(rateLimit)
app.use(auth as RequestHandler)
if (!env.ALLOW_INDEXING) {
app.use((_, res, next) => {
res.set("X-Robots-Tag", "noindex, nofollow")
next()
})
}
async function getBuild() {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const build = viteDevServer
? viteDevServer.ssrLoadModule("virtual:remix/server-build")
: // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore-error this should exist before running the server
// but it may not exist just yet.
// eslint-disable-next-line import/no-unresolved
await import("../build/server/index.js")
return build as unknown as ServerBuild
}
app.all(
"*",
createRequestHandler({
getLoadContext: (_req: Request, res: Response) => ({
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
cspNonce: res.locals.cspNonce,
serverBuild: getBuild(),
}),
mode: env.NODE_ENV,
build: getBuild,
}) as RequestHandler,
)
const desiredPort = env.SERVER_PORT
const portToUse = await getPort({
port: portNumbers(desiredPort, desiredPort + 100),
})
const portAvailable = desiredPort === portToUse
if (!portAvailable && env.NODE_ENV !== "development") {
console.log(`⚠️ Port ${desiredPort} is not available.`)
process.exit(1)
}
const server = app.listen(portToUse, () => {
if (!portAvailable) {
console.warn(
chalk.yellow(
`⚠️ Port ${desiredPort} is not available, using ${portToUse} instead.`,
),
)
}
console.log(`🚀 We have liftoff!`)
const localUrl = `http://localhost:${portToUse}`
let lanUrl: string | null = null
const localIp = ipAddress() ?? "Unknown"
// Check if the address is a private ip
// https://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces
// https://github.com/facebook/create-react-app/blob/d960b9e38c062584ff6cfb1a70e1512509a966e7/packages/react-dev-utils/WebpackDevServerUtils.js#LL48C9-L54C10
if (/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(localIp)) {
lanUrl = `http://${localIp}:${portToUse}`
}
console.log(
`
${chalk.bold("Local:")} ${chalk.cyan(localUrl)}
${lanUrl ? `${chalk.bold("On Your Network:")} ${chalk.cyan(lanUrl)}` : ""}
${chalk.bold("Press Ctrl+C to stop")}
`.trim(),
)
initCronjobs()
})
closeWithGrace(async () => {
await new Promise((resolve, reject) => {
server.close((e) => (e ? reject(e) : resolve("ok")))
})
})
from remix.
Related Issues (20)
- Unstable loader operation HOT 2
- Application error on throwing response on splat route HOT 2
- Express Template: Oh no! There was a problem fetching the file from GitHub. The request responded with a 403 status. Please try again later. HOT 1
- Remix not properly aborting requests on single fetch HOT 4
- SingleFetch Fetcher State Issue in Remix: Missing Loading State After Submission HOT 2
- Fonts laying ontop of each other on the Remix-run website HOT 1
- `.client` module splitting doesn't respect `app` directory
- useRoutes and matchRoutes give different results in remix HOT 2
- Error: link rel=preload has an invalid `href` value HOT 2
- public assets are served from a different url on dev than in the build
- HMR causes infinite render loop with nested Awaits HOT 1
- Remix CLI required for `remix build`, but only available in `@remix-run/dev` HOT 1
- Type instantiation is excessively deep and possibly infinite.ts(2589) when using readonly HOT 4
- Browser addons injecting html cause hydration errors HOT 3
- Multiple remix dev servers in one express application
- Using `createCookie` in a route module causes `fetcher.Form` to do a document reload on submission HOT 2
- Loader request not cancelled when streaming promises Single Fetch HOT 3
- Single Fetch throwing response does not work HOT 9
- Single Fetch's useRouteLoaderData return type is missing undefined HOT 4
- Vite dependency optimization is causing errors in development HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from remix.