Skip to content
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

Make dev and prod routes consistent #142

Merged
merged 8 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/test-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
branches:
- 'main'
pull_request:
types:
- opened
jobs:
test:
env:
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.8'
services:
mongodb:
image: 'mongo'
Expand Down
4 changes: 2 additions & 2 deletions env-example/frontend.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
VITE_API_URL=http://localhost:8080
VITE_API_URL=http://localhost:8080/api
VITE_NMRIUM_URL=http://localhost:3000

#Set true if corresponding NOMAD modules are used
VITE_SUBMIT_ON=true
VITE_BATCH_SUBMIT_ON=true
VITE_DATASTORE_ON=true
VITE_DATASTORE_ON=true
9 changes: 4 additions & 5 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ http {
}

location /api/ {
proxy_pass http://api:8080/;
proxy_pass http://api:8080;
}

location /data/ {
Expand All @@ -68,15 +68,15 @@ http {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

proxy_pass http://api:8080/socket.io/;
proxy_pass http://api:8080/socket.io/;
}

location /downloads {
alias /app/downloads;
}



error_page 404 /404.html;
location = /404.html {
}
Expand All @@ -88,4 +88,3 @@ http {


}

3 changes: 1 addition & 2 deletions nginx.conf-tls
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ http {
}

location /api/ {
proxy_pass http://api:8080/;
proxy_pass http://api:8080;
}

location /socket.io/ {
Expand All @@ -97,4 +97,3 @@ http {
}

}

36 changes: 18 additions & 18 deletions nomad-rest-api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,24 @@ app.use((req, res, next) => {
next()
})

app.use('/tracker', trackerRoutes)
app.use('/admin/instruments', instrumentsRoutes)
app.use('/dash', dashRoutes)
app.use('/auth', authRoutes)
app.use('/submit', submitRoutes)
app.use('/admin/users', usersRoutes)
app.use('/admin/groups', groupsRoutes)
app.use('/admin/history', historyRoutes)
app.use('/admin/param-sets', paramSetsRoutes)
app.use('/admin/accounts', accountsRoutes)
app.use('/admin/message', messageRoutes)
app.use('/batch-submit', batchSubmitRoutes)
app.use('/data', dataRoutes)
app.use('/search', searchRoutes)
app.use('/claims', claimRoutes)
app.use('/datasets', datasetsRoutes)
app.use('/stats', statsRoutes)
app.use('/collections', collectionRoutes)
app.use('/api/tracker', trackerRoutes)
app.use('/api/admin/instruments', instrumentsRoutes)
app.use('/api/dash', dashRoutes)
app.use('/api/auth', authRoutes)
app.use('/api/submit', submitRoutes)
app.use('/api/admin/users', usersRoutes)
app.use('/api/admin/groups', groupsRoutes)
app.use('/api/admin/history', historyRoutes)
app.use('/api/admin/param-sets', paramSetsRoutes)
app.use('/api/admin/accounts', accountsRoutes)
app.use('/api/admin/message', messageRoutes)
app.use('/api/batch-submit', batchSubmitRoutes)
app.use('/api/data', dataRoutes)
app.use('/api/search', searchRoutes)
app.use('/api/claims', claimRoutes)
app.use('/api/datasets', datasetsRoutes)
app.use('/api/stats', statsRoutes)
app.use('/api/collections', collectionRoutes)

app.use((req, res) => {
res.status(404).send()
Expand Down
4 changes: 2 additions & 2 deletions nomad-rest-api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nomad-rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@
"supertest": "^7.0.0",
"vitest": "^1.3.1"
}
}
}
56 changes: 28 additions & 28 deletions nomad-rest-api/tests/accounts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ beforeEach(setupDB)

describe('GET /accounts/data', () => {
it('should fail with status code 403 if user is not authorised', async () => {
await request(app).get('/admin/accounts/data').expect(403)
await request(app).get('/api/admin/accounts/data').expect(403)
})

it('should fail with status code 403 if user is authorised by user without admin privileges', async () => {
await request(app)
.get('/admin/accounts/data')
.get('/api/admin/accounts/data')
.set('Authorization', `Bearer ${testUserOne.tokens[0].token}`)
.expect(403)
})

it('should return data array of length 2 with the first object corresponding to testGroupTwo', async () => {
const { body } = await request(app)
.get('/admin/accounts/data/?groupId=undefined')
.get('/api/admin/accounts/data/?groupId=undefined')
.set('Authorization', `Bearer ${testUserAdmin.tokens[0].token}`)
.expect(200)

Expand All @@ -41,7 +41,7 @@ describe('GET /accounts/data', () => {

it('should return data array of length 2 the first object corresponding to testUserThree', async () => {
const { body } = await request(app)
.get('/admin/accounts/data/?groupId=' + testGroupTwo._id)
.get('/api/admin/accounts/data/?groupId=' + testGroupTwo._id)
.set('Authorization', `Bearer ${testUserAdmin.tokens[0].token}`)
.expect(200)

Expand All @@ -54,19 +54,19 @@ describe('GET /accounts/data', () => {

describe('GET /accounts/instruments-costing', () => {
it('should fail with status code 403 if user is not authorised', async () => {
await request(app).get('/admin/accounts/instruments-costing').expect(403)
await request(app).get('/api/admin/accounts/instruments-costing').expect(403)
})

it('should fail with status code 403 if user is authorised by user without admin privileges', async () => {
await request(app)
.get('/admin/accounts/instruments-costing')
.get('/api/admin/accounts/instruments-costing')
.set('Authorization', `Bearer ${testUserOne.tokens[0].token}`)
.expect(403)
})

it('should data array of length 2 the first object corresponding to testInstrumentOne', async () => {
const { body } = await request(app)
.get('/admin/accounts/instruments-costing')
.get('/api/admin/accounts/instruments-costing')
.set('Authorization', `Bearer ${testUserAdmin.tokens[0].token}`)
.expect(200)

Expand All @@ -78,12 +78,12 @@ describe('GET /accounts/instruments-costing', () => {

describe('PUT /accounts/instruments-costing', () => {
it('should fail with status code 403 if user is not authorised', async () => {
await request(app).put('/admin/accounts/instruments-costing').expect(403)
await request(app).put('/api/admin/accounts/instruments-costing').expect(403)
})

it('should fail with status code 403 if user is authorised by user without admin privileges', async () => {
await request(app)
.put('/admin/accounts/instruments-costing')
.put('/api/admin/accounts/instruments-costing')
.set('Authorization', `Bearer ${testUserOne.tokens[0].token}`)
.expect(403)
})
Expand All @@ -94,7 +94,7 @@ describe('PUT /accounts/instruments-costing', () => {
reqData[testInstrThree.name] = testInstrThree.cost

await request(app)
.put('/admin/accounts/instruments-costing')
.put('/api/admin/accounts/instruments-costing')
.send(reqData)
.set('Authorization', `Bearer ${testUserAdmin.tokens[0].token}`)
.expect(200)
Expand All @@ -108,19 +108,19 @@ describe('PUT /accounts/instruments-costing', () => {

describe('POST /accounts/grants', () => {
it('should fail with status code 403 if user is not authorised', async () => {
await request(app).post('/admin/accounts/grants').expect(403)
await request(app).post('/api/admin/accounts/grants').expect(403)
})

it('should fail with status code 403 if user is authorised by user without admin privileges', async () => {
await request(app)
.post('/admin/accounts/grants')
.post('/api/admin/accounts/grants')
.set('Authorization', `Bearer ${testUserOne.tokens[0].token}`)
.expect(403)
})

it('should fail with status code 422 if grantCode of testGrantOne is provided', async () => {
const { body } = await request(app)
.post('/admin/accounts/grants')
.post('/api/admin/accounts/grants')
.send({ grantCode: testGrantOne.grantCode })
.set('Authorization', `Bearer ${testUserAdmin.tokens[0].token}`)
.expect(422)
Expand All @@ -130,7 +130,7 @@ describe('POST /accounts/grants', () => {

it('should add a new grant into DB', async () => {
const { body } = await request(app)
.post('/admin/accounts/grants')
.post('/api/admin/accounts/grants')
.send({ grantCode: 'XX-test-3-YY', include: [] })
.set('Authorization', `Bearer ${testUserAdmin.tokens[0].token}`)
.expect(200)
Expand All @@ -141,7 +141,7 @@ describe('POST /accounts/grants', () => {

it('should fail with status code 409 includes property contains testUserOne', async () => {
const { body } = await request(app)
.post('/admin/accounts/grants')
.post('/api/admin/accounts/grants')
.send({
grantCode: 'XX-test-3-YY',
include: [
Expand All @@ -163,19 +163,19 @@ describe('POST /accounts/grants', () => {

describe('GET /accounts/grants', () => {
it('should fail with status code 403 if user is not authorised', async () => {
await request(app).get('/admin/accounts/grants').expect(403)
await request(app).get('/api/admin/accounts/grants').expect(403)
})

it('should fail with status code 403 if user is authorised by user without admin privileges', async () => {
await request(app)
.get('/admin/accounts/grants')
.get('/api/admin/accounts/grants')
.set('Authorization', `Bearer ${testUserOne.tokens[0].token}`)
.expect(403)
})

it('should get array of 2 objects', async () => {
const { body } = await request(app)
.get('/admin/accounts/grants')
.get('/api/admin/accounts/grants')
.set('Authorization', `Bearer ${testUserAdmin.tokens[0].token}`)
.expect(200)

Expand All @@ -187,20 +187,20 @@ describe('GET /accounts/grants', () => {
describe('DELETE /accounts/grants/:grantId', () => {
it('should fail with status code 403 if user is not authorised', async () => {
await request(app)
.delete('/admin/accounts/grants/' + testGrantOne._id.toString())
.delete('/api/admin/accounts/grants/' + testGrantOne._id.toString())
.expect(403)
})

it('should fail with status code 403 if user is authorised by user without admin privileges', async () => {
await request(app)
.delete('/admin/accounts/grants/' + testGrantOne._id.toString())
.delete('/api/admin/accounts/grants/' + testGrantOne._id.toString())
.set('Authorization', `Bearer ${testUserOne.tokens[0].token}`)
.expect(403)
})

it('should testGrantOne if corresponding id is provided', async () => {
const { body } = await request(app)
.delete('/admin/accounts/grants/' + testGrantOne._id.toString())
.delete('/api/admin/accounts/grants/' + testGrantOne._id.toString())
.set('Authorization', `Bearer ${testUserAdmin.tokens[0].token}`)
.expect(200)

Expand All @@ -216,19 +216,19 @@ describe('DELETE /accounts/grants/:grantId', () => {

describe('PUT/ /accounts/grants/', () => {
it('should fail with status code 403 if user is not authorised', async () => {
await request(app).put('/admin/accounts/grants').expect(403)
await request(app).put('/api/admin/accounts/grants').expect(403)
})

it('should fail with status code 403 if user is authorised by user without admin privileges', async () => {
await request(app)
.put('/admin/accounts/grants')
.put('/api/admin/accounts/grants')
.set('Authorization', `Bearer ${testUserOne.tokens[0].token}`)
.expect(403)
})

it('should fail with status code 409 if user is authorised by user without admin privileges', async () => {
const { body } = await request(app)
.put('/admin/accounts/grants')
.put('/api/admin/accounts/grants')
.send({
_id: testGrantTwo._id,
include: [
Expand All @@ -249,7 +249,7 @@ describe('PUT/ /accounts/grants/', () => {

it('should should update testGrantTwo', async () => {
const { body } = await request(app)
.put('/admin/accounts/grants')
.put('/api/admin/accounts/grants')
.send({
_id: testGrantTwo._id,
include: [
Expand Down Expand Up @@ -280,19 +280,19 @@ describe('PUT/ /accounts/grants/', () => {

describe('GET /accounts/grants-costs', () => {
it('should fail with status code 403 if user is not authorised', async () => {
await request(app).get('/admin/accounts/grants-costs').expect(403)
await request(app).get('/api/admin/accounts/grants-costs').expect(403)
})

it('should fail with status code 403 if user is authorised by user without admin privileges', async () => {
await request(app)
.get('/admin/accounts/grants-costs')
.get('/api/admin/accounts/grants-costs')
.set('Authorization', `Bearer ${testUserOne.tokens[0].token}`)
.expect(403)
})

it('should return grants costs calculation data object', async () => {
const { body } = await request(app)
.get('/admin/accounts/grants-costs')
.get('/api/admin/accounts/grants-costs')
.set('Authorization', `Bearer ${testUserAdmin.tokens[0].token}`)
.expect(200)

Expand Down
Loading