Repository navigation
fix: wire Conduit to the Spring Boot 3 backend (#1258) locally #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devin/task-19-eslint-ci-on-overrides
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /** | ||
| * Seeds a local RealWorld backend (default http://localhost:8080) with users, | ||
| * follows, tagged articles (enough for pagination), comments and favorites. | ||
| * | ||
| * Usage: API_URL=http://localhost:8080 bun scripts/seed-local.ts | ||
| */ | ||
| const API_URL = process.env['API_URL'] ?? 'http://localhost:8080'; | ||
| const PASSWORD = 'password123'; | ||
| const USERS = ['jake', 'ana', 'sam']; | ||
|
Comment on lines
+8
to
+9
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👁️ TD Information Security: Published credentials for seeded accounts Running View in Devin Review · Custom reviewer Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| const TAGS = ['angular', 'spring', 'java', 'rxjs', 'testing']; | ||
| const ARTICLES_PER_USER = 9; | ||
|
|
||
| async function call<T>(method: string, path: string, body?: unknown, token?: string): Promise<T> { | ||
| const res = await fetch(`${API_URL}${path}`, { | ||
| method, | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| ...(token ? { Authorization: `Token ${token}` } : {}), | ||
| }, | ||
| body: body === undefined ? undefined : JSON.stringify(body), | ||
| }); | ||
| if (!res.ok) { | ||
| throw new Error(`${method} ${path} -> ${res.status} ${await res.text()}`); | ||
| } | ||
| return (res.status === 204 ? undefined : await res.json()) as T; | ||
| } | ||
|
|
||
| async function signIn(username: string): Promise<string> { | ||
| const user = { username, email: `${username}@example.com`, password: PASSWORD }; | ||
| try { | ||
| return (await call<{ user: { token: string } }>('POST', '/users', { user })).user.token; | ||
| } catch { | ||
| const { email, password } = user; | ||
| return (await call<{ user: { token: string } }>('POST', '/users/login', { user: { email, password } })).user.token; | ||
| } | ||
| } | ||
|
|
||
| async function main(): Promise<void> { | ||
| const tokens: Record<string, string> = {}; | ||
| for (const username of USERS) { | ||
| tokens[username] = await signIn(username); | ||
| } | ||
|
|
||
| const [jake, ana, sam] = USERS; | ||
| await call('POST', `/profiles/${ana}/follow`, {}, tokens[jake]); | ||
| await call('POST', `/profiles/${sam}/follow`, {}, tokens[jake]); | ||
| await call('POST', `/profiles/${jake}/follow`, {}, tokens[ana]); | ||
|
|
||
| const slugs: string[] = []; | ||
| for (const [u, username] of USERS.entries()) { | ||
| for (let i = 1; i <= ARTICLES_PER_USER; i++) { | ||
| const article = { | ||
| title: `${username} seed article ${i} ${Date.now()}`, | ||
| description: `Seed article ${i} by ${username}`, | ||
| body: `# Seed article ${i}\n\nWritten by **${username}** for local runs.`, | ||
| tagList: [TAGS[(u + i) % TAGS.length], TAGS[(u + i + 1) % TAGS.length]], | ||
| }; | ||
| const { article: created } = await call<{ article: { slug: string } }>( | ||
| 'POST', | ||
| '/articles', | ||
| { article }, | ||
| tokens[username], | ||
| ); | ||
| slugs.push(created.slug); | ||
| } | ||
| } | ||
|
|
||
| for (const [i, slug] of slugs.entries()) { | ||
| const commenter = USERS[(i + 1) % USERS.length]; | ||
| await call('POST', `/articles/${slug}/comments`, { comment: { body: `Nice post (${i + 1})` } }, tokens[commenter]); | ||
| if (i % 3 === 0) { | ||
| await call('POST', `/articles/${slug}/favorite`, {}, tokens[commenter]); | ||
| } | ||
| } | ||
|
|
||
| console.log( | ||
| `Seeded ${API_URL}: users ${USERS.join(', ')} (password "${PASSWORD}"), ${slugs.length} articles, tags ${TAGS.join(', ')}`, | ||
| ); | ||
| } | ||
|
|
||
| main().catch(err => { | ||
| console.error(err); | ||
| process.exit(1); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { HttpInterceptorFn } from '@angular/common/http'; | ||
| import { environment } from '../../../environments/environment'; | ||
|
|
||
| export const apiInterceptor: HttpInterceptorFn = (req, next) => { | ||
| const apiReq = req.clone({ url: `https://api.realworld.show/api${req.url}` }); | ||
| const apiReq = req.clone({ url: `${environment.apiUrl}${req.url}` }); | ||
| return next(apiReq); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| export interface Errors { | ||
| errors: Record<string, string>; | ||
| errors: Record<string, string | string[]>; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,7 @@ export class ArticlesService { | |
| } | ||
|
|
||
| create(article: Partial<Article>): Observable<Article> { | ||
| return this.http.post<{ article: Article }>('/articles/', { article: article }).pipe(map(data => data.article)); | ||
| return this.http.post<{ article: Article }>('/articles', { article: article }).pipe(map(data => data.article)); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔍 Remaining mocks miss revised endpoints After this change, the creation network-error mock still matches Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| } | ||
|
|
||
| update(article: Partial<Article>): Observable<Article> { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export const environment = { | ||
| production: false, | ||
| apiUrl: 'http://localhost:8080', | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export const environment = { | ||
| production: true, | ||
| apiUrl: 'https://api.realworld.show/api', | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔍 Automatic E2E startup uses public backend
Without an existing frontend server, setting
API_URLchanges helpers and mocks but leaves browser requests targeting the public API. The webServer configuration launchesnpm run start, which selects the default environment. Local E2E execution therefore requires a separately runningstart:localserver.Was this helpful? React with 👍 or 👎 to provide feedback.