Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SACI
frontend
Commits
338bf914
Commit
338bf914
authored
8 months ago
by
pedro f
Browse files
Options
Downloads
Patches
Plain Diff
make api_host configurable
parent
82ab1554
No related branches found
No related tags found
1 merge request
!2
/analysis route integration
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+19
-23
19 additions, 23 deletions
README.md
next.config.mjs
+1
-1
1 addition, 1 deletion
next.config.mjs
src/app/analysis/[id]/page.js
+2
-4
2 additions, 4 deletions
src/app/analysis/[id]/page.js
with
22 additions
and
28 deletions
README.md
+
19
−
23
View file @
338bf914
## Configuration
## Configuration
This sucks, but we'll come up with something better later.
1.
Create a
`.env.local`
file in the root directory of the project:
```
bash
# API host for internal requests.
#
# For example, if the API is running on localhost:8080,
# set INTERNAL_API_HOST=localhost:8080.
#
# If the API is running as a docker compose service called "api",
# set INTERNAL_API_HOST=api:8080.
INTERNAL_API_HOST
=
1.
Set the API host in
`next.config.mjs`
:
# API host for public requests.
```
js
#
/* next.config.mjs */
# This is the host that the client will use to make requests to the API.
const
nextConfig
=
{
# It is needed because the client connects to the API from the browser
// ...
# for websocket connections.
async
rewrites
()
{
#
return
[
# For example, if the API is running on saci.inf.ufpr.br:8080,
{
# set NEXT_PUBLIC_API_HOST=saci.inf.ufpr.br:8080.
source
:
"
/api/:path*
"
,
NEXT_PUBLIC_API_HOST
=
destination
:
"
http{s}://{api_host}/:path*
"
,
},
];
},
};
```
```
2.
Set the API host in
`src/app/analysis/[id]/page.js`
:
```
js
/* src/app/analysis/[id]/page.js */
const
api_host
=
"
{api_host}
"
;
// ...
```
e.g. api_host = "localhost:8080"
## Development
## Development
...
...
This diff is collapsed.
Click to expand it.
next.config.mjs
+
1
−
1
View file @
338bf914
...
@@ -4,7 +4,7 @@ const nextConfig = {
...
@@ -4,7 +4,7 @@ const nextConfig = {
return
[
return
[
{
{
source
:
"
/api/:path*
"
,
source
:
"
/api/:path*
"
,
destination
:
"
http://
localhost:8080
/:path*
"
,
destination
:
`
http://
${
process
.
env
.
INTERNAL_API_HOST
}
/:path*
`
,
},
},
];
];
},
},
...
...
This diff is collapsed.
Click to expand it.
src/app/analysis/[id]/page.js
+
2
−
4
View file @
338bf914
...
@@ -6,8 +6,6 @@ import { notFound } from "next/navigation";
...
@@ -6,8 +6,6 @@ import { notFound } from "next/navigation";
import
"
@/styles/analysis/activity-timeline.css
"
;
import
"
@/styles/analysis/activity-timeline.css
"
;
import
"
@/styles/analysis/page.css
"
;
import
"
@/styles/analysis/page.css
"
;
const
api_host
=
"
localhost:8080
"
;
export
default
function
Analysis
({
params
:
{
id
}
})
{
export
default
function
Analysis
({
params
:
{
id
}
})
{
const
[
report
,
setReport
]
=
useState
(
null
);
const
[
report
,
setReport
]
=
useState
(
null
);
const
[
failed
,
setFailed
]
=
useState
(
false
);
const
[
failed
,
setFailed
]
=
useState
(
false
);
...
@@ -21,7 +19,7 @@ export default function Analysis({ params: { id } }) {
...
@@ -21,7 +19,7 @@ export default function Analysis({ params: { id } }) {
},
[
failed
]);
},
[
failed
]);
useEffect
(()
=>
{
useEffect
(()
=>
{
const
ws
=
new
WebSocket
(
`ws://
${
api_host
}
/status/
${
id
}
`
);
const
ws
=
new
WebSocket
(
`ws://
${
process
.
env
.
NEXT_PUBLIC_API_HOST
}
/status/
${
id
}
`
);
ws
.
onmessage
=
(
event
)
=>
{
ws
.
onmessage
=
(
event
)
=>
{
setReport
(
JSON
.
parse
(
event
.
data
));
setReport
(
JSON
.
parse
(
event
.
data
));
...
@@ -71,7 +69,7 @@ export default function Analysis({ params: { id } }) {
...
@@ -71,7 +69,7 @@ export default function Analysis({ params: { id } }) {
}
}
function
validateId
(
id
,
setFailed
)
{
function
validateId
(
id
,
setFailed
)
{
fetch
(
`http
s
://
${
api_host
}
/analysis/
${
id
}
`
,
{
cache
:
'
no-store
'
})
fetch
(
`http://
${
process
.
env
.
NEXT_PUBLIC_API_HOST
}
/analysis/
${
id
}
`
,
{
cache
:
'
no-store
'
})
.
then
((
res
)
=>
{
.
then
((
res
)
=>
{
if
(
!
res
.
ok
)
{
if
(
!
res
.
ok
)
{
throw
new
Error
(
`Failed to validate id: got
${
res
.
status
}
response from api`
);
throw
new
Error
(
`Failed to validate id: got
${
res
.
status
}
response from api`
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment