Skip to content

Commit

Permalink
Type routes.js
Browse files Browse the repository at this point in the history
  • Loading branch information
valtterikantanen committed Aug 22, 2024
1 parent 9847ba9 commit 45acf19
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 92 deletions.
2 changes: 1 addition & 1 deletion services/backend/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const express = require('express')
const { baseUrl, backendPort } = require('./config')
const { initializeDatabaseConnection, dbConnections } = require('./database/connection')
const { startCron } = require('./events')
const routes = require('./routes')
const routes = require('./routes').default
const logger = require('./util/logger')
require('./worker/worker')

Expand Down
91 changes: 0 additions & 91 deletions services/backend/src/routes.js

This file was deleted.

145 changes: 145 additions & 0 deletions services/backend/src/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import * as Sentry from '@sentry/node'
import compression from 'compression'
import cors from 'cors'
import express, { Express } from 'express'

import { frontUrl, serviceProvider } from './config'
import accessLogger from './middleware/accessLogger'
import * as auth from './middleware/auth'
import currentUserMiddleware from './middleware/currentUser'
import errorHandler from './middleware/errorHandler'
import headersMiddleware from './middleware/headers'
import changelog from './routes/changelog'
import closeToGraduation from './routes/closeToGraduation'
import completedCoursesSearch from './routes/completedCoursesSearch'
import courseExclusions from './routes/courseExclusions'
import courses from './routes/courses'
import curriculumPeriods from './routes/curriculumPeriods'
import customOpenUniSearch from './routes/customOpenUniSearch'
import customPopulationSearch from './routes/customPopulationSearch'
import faculties from './routes/faculties'
import feedback from './routes/feedback'
import languageCenterData from './routes/languageCenterData'
import login from './routes/login'
import population from './routes/population'
import programmeModules from './routes/programmeModules'
import providers from './routes/providers'
import semesters from './routes/semesters'
import students from './routes/students'
import studyGuidanceGroups from './routes/studyGuidanceGroups'
import studyProgramme from './routes/studyProgramme'
import studyProgrammeCriteria from './routes/studyProgrammeCriteria'
import studyProgrammePins from './routes/studyProgrammePins'
import tags from './routes/tags'
import teachers from './routes/teachers'
import university from './routes/university'
import updater from './routes/updater'
import usersToska from './routes/users'
import usersFd from './routes/usersFd'
import initializeSentry from './util/sentry'

const routes = (app: Express, url: string) => {
initializeSentry(app)

app.use(Sentry.Handlers.requestHandler())
app.use(Sentry.Handlers.tracingHandler())

app.use(cors({ credentials: true, origin: frontUrl }))
app.use(express.json())
app.use(compression())

app.use(headersMiddleware)
app.use(currentUserMiddleware)
app.use(accessLogger)
app.use(`${url}/login`, login)
app.use(url, courses)
app.use(`${url}/students`, students)
app.use(url, population)
app.use(`${url}/providers`, providers)
app.use(`${url}/semesters/codes`, semesters)
app.use(url, tags)
app.use(url, programmeModules)
app.use(`${url}/v3/course_exclusions`, courseExclusions)
app.use(`${url}/v2/studyprogrammes`, studyProgramme)
app.use(`${url}/programmecriteria`, studyProgrammeCriteria)
app.use(`${url}/openunisearch`, auth.roles(['openUniSearch']), customOpenUniSearch)
app.use(`${url}/changelog`, changelog)
app.use(`${url}/completedcoursessearch`, completedCoursesSearch)
app.use(`${url}/languagecenterdata`, languageCenterData)
app.use(`${url}/faculties`, faculties)
app.use(`${url}/university`, university)
app.use(`${url}/updater`, auth.roles(['admin']), updater)
app.use(`${url}/teachers`, auth.roles(['teachers']), teachers)
if (serviceProvider === 'toska') {
app.use(`${url}/users`, usersToska)
} else {
app.use(`${url}/users`, usersToska)
app.use(`${url}/users`, usersFd)
}
app.use(`${url}/feedback`, feedback)
app.use(`${url}/custom-population-search`, customPopulationSearch)
app.use(`${url}/studyguidancegroups`, auth.roles(['studyGuidanceGroups']), studyGuidanceGroups)
app.use(`${url}/close-to-graduation`, auth.roles(['fullSisuAccess', 'studyGuidanceGroups']), closeToGraduation)
app.use(`${url}/study-programme-pins`, studyProgrammePins)
app.use(`${url}/curriculum-periods`, curriculumPeriods)
app.get('*', async (_, res) => {
const results = { error: 'unknown endpoint' }
res.status(404).json(results)
})
app.use(Sentry.Handlers.errorHandler())
app.use(errorHandler)
}

export default routes

// module.exports = (app, url) => {
// initializeSentry(app)

// app.use(Sentry.Handlers.requestHandler())
// app.use(Sentry.Handlers.tracingHandler())

// app.use(cors({ credentials: true, origin: frontUrl }))
// app.use(express.json())
// app.use(compression())

// app.use(headersMiddleware)
// app.use(currentUserMiddleware)
// app.use(accessLogger)
// app.use(`${url}/login`, login)
// app.use(url, courses)
// app.use(`${url}/students`, students)
// app.use(url, population)
// app.use(`${url}/providers`, providers)
// app.use(`${url}/semesters/codes`, semesters)
// app.use(url, tags)
// app.use(url, programmeModules)
// app.use(`${url}/v3/course_exclusions`, courseExclusions)
// app.use(`${url}/v2/studyprogrammes`, studyProgramme)
// app.use(`${url}/programmecriteria`, studyProgrammeCriteria)
// app.use(`${url}/openunisearch`, auth.roles(['openUniSearch']), customOpenUniSearch)
// app.use(`${url}/changelog`, changelog)
// app.use(`${url}/completedcoursessearch`, completedCoursesSearch)
// app.use(`${url}/languagecenterdata`, languageCenterData)
// app.use(`${url}/faculties`, faculties)
// app.use(`${url}/university`, university)
// app.use(`${url}/updater`, auth.roles(['admin']), updater)
// app.use(`${url}/teachers`, auth.roles(['teachers']), teachers)
// if (serviceProvider === 'toska') {
// app.use(`${url}/users`, usersToska)
// } else {
// app.use(`${url}/users`, usersToska)
// app.use(`${url}/users`, usersFd)
// }
// app.use(`${url}/feedback`, feedback)
// app.use(`${url}/custom-population-search`, customPopulationSearch)
// app.use(`${url}/studyguidancegroups`, auth.roles(['studyGuidanceGroups']), studyGuidanceGroups)
// app.use(`${url}/close-to-graduation`, auth.roles(['fullSisuAccess', 'studyGuidanceGroups']), closeToGraduation)
// app.use(`${url}/study-programme-pins`, studyProgrammePins)
// app.use(`${url}/curriculum-periods`, curriculumPeriods)
// app.get('*', async (_, res) => {
// const results = { error: 'unknown endpoint' }
// res.status(404).json(results)
// })
// app.use(Sentry.Handlers.errorHandler())
// app.use(errorHandler)
// }

0 comments on commit 45acf19

Please sign in to comment.