Unable to run stacker.news locally #917
Replies: 61 comments 3 replies
-
They should still work. I usually only run the database as a container and run the app and worker via Looking at your logs, it seems like something is wrong with your database container:
That's why the app container exits since it requires the db container to be up. I guess the same error shows up if you try to only get the database up with |
Beta Was this translation helpful? Give feedback.
-
This is probably how we should setup our future dev env. Run app/worker locally and run all the other config-nightmare services in docker. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the answers.
I'm trying the other approach. Currently managed to run the database as a container ( |
Beta Was this translation helpful? Give feedback.
-
Actually, while I was resolving the issues that i encountered when using the EDIT: My hunch seems confirmed, I had to run |
Beta Was this translation helpful? Give feedback.
-
Cool. I'm going be putting a lot of effort into making this as easy as I can soon. If you have any more feedback I'd appreciate it! |
Beta Was this translation helpful? Give feedback.
-
Well, if you are ok with more feedback, the new error I get is this one:
I checked that EDIT: Seems like i need to locate the correct |
Beta Was this translation helpful? Give feedback.
-
I tried mindlessly following the local development steps but it didn't work as well. It appears to be a different error so I'm not sure if I should open another issue. I'll try to debug exactly where the error happens later but, for now, here's a (not that helpful) screenshot. |
Beta Was this translation helpful? Give feedback.
-
One more screenshot. I think this one might be helpful: Output for |
Beta Was this translation helpful? Give feedback.
-
Hey, @huumn, here's a more detailed output. Let me know if you need more details.
|
Beta Was this translation helpful? Give feedback.
-
If you want, checkout this branch: https://github.com/stackernews/stacker.news/tree/localdev Then run It has a number of refinements to the docker setup that should make it more reliable and deterministic (in addition to populating db/search with a seed). |
Beta Was this translation helpful? Give feedback.
-
Cool, I'm trying it at this moment! I'll tell how it went Right away it's showing a couple db errors like this one:
but I don't know if it's going to affect the final build |
Beta Was this translation helpful? Give feedback.
-
Hmm, it did! Output for |
Beta Was this translation helpful? Give feedback.
-
I'm trying to pinpoint where the problem happens but haven't found anything useful yet. But this
Full log:
|
Beta Was this translation helpful? Give feedback.
-
You probably need to delete all of your existing containers. The db container needs to be rebuilt so it imports the db seed. |
Beta Was this translation helpful? Give feedback.
-
Oh, makes sense. I'll try! Maybe adding a new command to sndev to reset the environment would help. Something like |
Beta Was this translation helpful? Give feedback.
-
Mhh, not sure why the CSP would block these requests which are essential for the app to load. Those are the ones using nonces. If your browser doesn't support CSP nonces, it should fall back to host-based matching, so only inline scripts and scripts from the same domain are allowed:
-- https://csp.withgoogle.com/docs/strict-csp.html Does CSP also block the requests in Chrome? You could try to disable the CSP using this patch: patchdiff --git a/middleware.js b/middleware.js
index 858b80e4..2810b41c 100644
--- a/middleware.js
+++ b/middleware.js
@@ -19,44 +19,44 @@ export function middleware (request) {
resp = referrerMiddleware(request)
}
- const nonce = Buffer.from(crypto.randomUUID()).toString('base64')
- const cspHeader = [
- // if something is not explicitly allowed, we don't allow it.
- "default-src 'none'",
- "font-src 'self' a.stacker.news",
- // we want to load images from everywhere but we can limit to HTTPS at least
- "img-src 'self' a.stacker.news m.stacker.news https: data: blob:",
- "media-src 'self' a.stacker.news m.stacker.news",
- // Using nonces and strict-dynamic deploys a strict CSP.
- // see https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html#strict-policy.
- // Old browsers will ignore nonce and strict-dynamic and fallback to host-based matching and unsafe-inline
- process.env.NODE_ENV === 'production'
- ? `script-src 'self' 'unsafe-inline' 'nonce-${nonce}' 'strict-dynamic' https:`
- // unsafe-eval is required during development due to react-refresh.js
- // see https://github.com/vercel/next.js/issues/14221
- : `script-src 'self' 'unsafe-inline' 'unsafe-eval' 'nonce-${nonce}' 'strict-dynamic' https:`,
- // unsafe-inline for styles is not ideal but okay if script-src is using nonces
- "style-src 'self' a.stacker.news 'unsafe-inline'",
- "manifest-src 'self'",
- 'frame-src www.youtube.com platform.twitter.com',
- "connect-src 'self' https: wss:",
- // disable dangerous plugins like Flash
- "object-src 'none'",
- // blocks injection of <base> tags
- "base-uri 'none'",
- // tell user agents to replace HTTP with HTTPS
- 'upgrade-insecure-requests',
- // prevents any domain from framing the content (defense against clickjacking attacks)
- "frame-ancestors 'none'"
- ].join('; ')
-
- resp.headers.set('Content-Security-Policy', cspHeader)
- // for browsers that don't support CSP
- resp.headers.set('X-Frame-Options', 'DENY')
- // more useful headers
- resp.headers.set('X-Content-Type-Options', 'nosniff')
- resp.headers.set('Referrer-Policy', 'origin-when-cross-origin')
- resp.headers.set('Strict-Transport-Security', 'max-age=31536000; includeSubDomains')
+ // const nonce = Buffer.from(crypto.randomUUID()).toString('base64')
+ // const cspHeader = [
+ // // if something is not explicitly allowed, we don't allow it.
+ // "default-src 'none'",
+ // "font-src 'self' a.stacker.news",
+ // // we want to load images from everywhere but we can limit to HTTPS at least
+ // "img-src 'self' a.stacker.news m.stacker.news https: data: blob:",
+ // "media-src 'self' a.stacker.news m.stacker.news",
+ // // Using nonces and strict-dynamic deploys a strict CSP.
+ // // see https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html#strict-policy.
+ // // Old browsers will ignore nonce and strict-dynamic and fallback to host-based matching and unsafe-inline
+ // process.env.NODE_ENV === 'production'
+ // ? `script-src 'self' 'unsafe-inline' 'nonce-${nonce}' 'strict-dynamic' https:`
+ // // unsafe-eval is required during development due to react-refresh.js
+ // // see https://github.com/vercel/next.js/issues/14221
+ // : `script-src 'self' 'unsafe-inline' 'unsafe-eval' 'nonce-${nonce}' 'strict-dynamic' https:`,
+ // // unsafe-inline for styles is not ideal but okay if script-src is using nonces
+ // "style-src 'self' a.stacker.news 'unsafe-inline'",
+ // "manifest-src 'self'",
+ // 'frame-src www.youtube.com platform.twitter.com',
+ // "connect-src 'self' https: wss:",
+ // // disable dangerous plugins like Flash
+ // "object-src 'none'",
+ // // blocks injection of <base> tags
+ // "base-uri 'none'",
+ // // tell user agents to replace HTTP with HTTPS
+ // 'upgrade-insecure-requests',
+ // // prevents any domain from framing the content (defense against clickjacking attacks)
+ // "frame-ancestors 'none'"
+ // ].join('; ')
+ //
+ // resp.headers.set('Content-Security-Policy', cspHeader)
+ // // for browsers that don't support CSP
+ // resp.headers.set('X-Frame-Options', 'DENY')
+ // // more useful headers
+ // resp.headers.set('X-Content-Type-Options', 'nosniff')
+ // resp.headers.set('Referrer-Policy', 'origin-when-cross-origin')
+ // resp.headers.set('Strict-Transport-Security', 'max-age=31536000; includeSubDomains')
return resp
} Copy the content into a file and run Does that fix the issue? |
Beta Was this translation helpful? Give feedback.
-
Hmm, I tried it. It didn't work but now at least it thew a different error... Not sure yet if it's good or bad though 😅 Unfortunately I will not have time to help you debug it today but at least I can throw a couple screenshots here. I also attached an asciinema recording with the output of |
Beta Was this translation helpful? Give feedback.
-
Can you share your browser versions when you get a chance? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I'm trying to run the I'm still trying things out so, for now, I'm only attaching a few screenshots of the parts that might be useful for debugging here. Let me know if you see anything suspicious in the logs |
Beta Was this translation helpful? Give feedback.
-
I think I'll try running it on a VM on QEMU or VirtualBox with a fresh install of Debian or Ubuntu or something. @ekzyis @huumn which distro would you recommend for this purpose? |
Beta Was this translation helpful? Give feedback.
-
The following error means that the variables
The error comes from here: stacker.news/api/search/index.js Lines 1 to 13 in 179a539
Mhh, I don't think we're doing anything special so I would say popular distros like Debian or Ubuntu sound like a good choice. |
Beta Was this translation helpful? Give feedback.
-
Yeah, I tried on another machine with Lubuntu 22.04 and it gave me the same errors :/ Later today I'll try on another workstation with Debian 12. If it doesn't work, I'll try firing up a VM with a non-Debian based distro to see what happens... Maybe Fedora or Rocky Linux which are Red Hat based |
Beta Was this translation helpful? Give feedback.
-
I also have a Mac Mini 2012 here somewhere. I think I'll try on it as well. Not today, maybe until the end of the week |
Beta Was this translation helpful? Give feedback.
-
I think there should be some documentation on how to run the app without using Docker. Better yet if it's not necessary to run all the parts, maybe just the Simple step-by-step instructions like "install node v18.x.x, PostgreSQL vX and etc" I think it might make the dev environment easier to understand and get up and running, specially for devs without much experience that just want to make a quick small contribution I'd like to help with that and I already started it by extracting the relevant parts from the docker-compose and Docker files. But I don't have much free time so it might take some time. |
Beta Was this translation helpful? Give feedback.
-
I'm trying with Docker again but now a new error has appeared. I still didn't have the time to try it on my mac mini Something related with me not having valid credentials to download I changed it from |
Beta Was this translation helpful? Give feedback.
-
Oh weird. My understanding was that we could run imgproxy pro in dev without credentials. Hrm. Okay, I'll have to update that. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Okay, please pull and try again. 806f42e doesn't use imgproxy pro and sets the opensearch username and password now. |
Beta Was this translation helpful? Give feedback.
-
I believe I just fixed the service worker error in 56c2682 |
Beta Was this translation helpful? Give feedback.
-
I seem to be getting lucky today and now I haven't gotten any failures to run on dev because of an unhealthy container since our conversation last night, but I'll keep an eye out and report back if I have any more issues. |
Beta Was this translation helpful? Give feedback.
-
Description
I wonder if the instructions here are still up to date. I don't seem to get the outcome that I would expect after running
docker-compose up --build
.Steps to Reproduce
I followed the first two steps (installed docker-compose and cloned the project from github).
Expected behavior
I get these last 3 messages in my console logs. Attaching the full console logs here too.
log.txt
I would expect the app not to exit so that I can access the site at
localhost:3000
.Environment:
If you only experience the issue on certain devices or browsers, provide that info.
Beta Was this translation helpful? Give feedback.
All reactions