Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
WIE_202021_CSBillero11
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Bernard Roland (Student Com20)
WIE_202021_CSBillero11
Commits
05cfbf46
Commit
05cfbf46
authored
3 years ago
by
Bernard Roland (Student Com20)
Browse files
Options
Downloads
Patches
Plain Diff
Fixed the CORS requests beeing blocked
parent
fa9e8c58
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/src/headers.ts
+12
-1
12 additions, 1 deletion
server/src/headers.ts
server/src/v1/auth.ts
+3
-3
3 additions, 3 deletions
server/src/v1/auth.ts
with
15 additions
and
4 deletions
server/src/headers.ts
+
12
−
1
View file @
05cfbf46
...
...
@@ -7,7 +7,18 @@ export function addDefaultHeaders(req: Request, res: Response, next: NextFunctio
const
origin
=
req
.
header
(
'
Origin
'
);
if
(
allowedOrigins
.
includes
(
'
*
'
)
||
origin
&&
allowedOrigins
.
includes
(
origin
))
{
res
.
header
(
'
Access-Control-Allow-Origin
'
,
origin
);
const
headers
=
req
.
header
(
'
Access-Control-Request-Headers
'
);
if
(
headers
)
{
res
.
header
(
'
Access-Control-Allow-Headers
'
,
headers
);
}
res
.
header
(
'
Access-Control-Allow-Methods
'
,
'
GET,HEAD,PUT,PATCH,POST,DELETE
'
);
res
.
header
(
'
Access-Control-Max-Age
'
,
'
86400
'
);
}
if
(
req
.
method
===
'
OPTIONS
'
)
{
// Handle preflight requests
res
.
send
();
}
else
{
next
();
}
next
();
}
This diff is collapsed.
Click to expand it.
server/src/v1/auth.ts
+
3
−
3
View file @
05cfbf46
...
...
@@ -69,7 +69,7 @@ auth.post('/register', async (req, res) => {
const
token
=
await
generateToken
({
id
:
id
});
await
database
(
'
users
'
).
insert
({
id
:
id
,
user_name
:
body
.
username
,
user_name
:
body
.
username
.
trim
()
,
passwd_hash
:
passwdHash
,
email
:
body
.
email
??
null
,
real_name
:
body
.
realname
??
null
,
...
...
@@ -102,7 +102,7 @@ auth.post('/token', async (req, res) => {
if
(
isOfType
<
TokenBody
>
(
req
.
body
,
[[
'
username
'
,
'
string
'
],
[
'
password
'
,
'
string
'
]]))
{
const
body
:
TokenBody
=
req
.
body
;
try
{
const
user
=
await
database
(
'
users
'
).
where
({
user_name
:
body
.
username
});
const
user
=
await
database
(
'
users
'
).
where
({
user_name
:
body
.
username
.
trim
()
});
if
(
user
.
length
===
1
)
{
if
(
await
compare
(
body
.
password
,
user
[
0
].
passwd_hash
))
{
const
token
=
await
generateToken
({
id
:
user
[
0
].
id
});
...
...
@@ -165,7 +165,7 @@ auth.put("/username", async function (req, res) {
const
body
:
UsernameBody
=
req
.
body
;
try
{
await
database
(
'
users
'
).
update
({
user_name
:
body
.
username
,
user_name
:
body
.
username
.
trim
()
,
}).
where
({
id
:
body
.
token
.
id
,
});
...
...
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