Commit 7ca47bb3 authored by Sandro Lutz's avatar Sandro Lutz Committed by scmoritz
Browse files

Add raven-js library

parent 442a73dd
......@@ -4,4 +4,5 @@ dist
.vscode
npm-debug.log
DOCUMENTATION.html
DOCUMENTATION.md
\ No newline at end of file
DOCUMENTATION.md
src/models/config.js
......@@ -6,6 +6,7 @@ stages:
before_script:
- npm install
- echo "$CONFIGURATION" > src/models/config.js
eslint:
stage: lint
......
......@@ -26,7 +26,8 @@
"mithril": "^1.1.5",
"polythene-css": "^1.0.0",
"polythene-mithril": "^1.0.0",
"marked": "^0.3.18"
"marked": "^0.3.18",
"raven-js": "^3.24.2"
},
"devDependencies": {
"babel-cli": "^6.26.0",
......
// src/index.js
import m from 'mithril';
import Raven from 'raven-js';
import { loadLanguage, currentLanguage, changeLanguage, isLanguageValid } from './models/language';
import { verbose } from './models/config';
import { verbose, sentryUrl } from './models/config';
import { Error404, Error401 } from './views/errors';
import { isLoggedIn } from './models/auth';
import studydocList from './views/studydocs/studydocList';
......@@ -25,134 +26,138 @@ import companyList from './views/companies/companyList';
import companyDetail from './views/companies/companyDetail';
import './views/styles/base.less';
loadLanguage();
Raven.config(sentryUrl).install();
if (verbose !== true) {
// set to pathname strategy (Please note that the production server needs to support this)
m.route.prefix('');
}
Raven.context(() => {
loadLanguage();
// routes which require authentication
const routesAuth = [
{
url: '/:language/studydocuments',
view: () => m(studydocList),
},
{
url: '/:language/studydocuments/new',
view: () => m(studydocNew),
},
{
url: '/:language/profile',
view: vnode => m(profile, vnode.attrs),
},
];
// routes without restrictions
const routes = [
{
url: '/:language',
view: () => m(amivLayout, m(frontpage)),
},
{
url: '/:language/amiv/statutes',
view: () => m(amivLayout, m(statutes)),
},
{
url: '/:language/amiv/board',
view: () => m(amivLayout, m(board)),
},
{
url: '/:language/amiv/commissions',
view: () => m(amivLayout, m(commissions)),
},
{
url: '/:language/amiv/about',
view: () => m(amivLayout, m(about)),
},
{
url: '/:language/contact',
view: () => m(contact),
},
{
url: '/:language/login',
view: () => m(login),
},
{
url: '/:language/logout',
view: () => m(logout),
},
{
url: '/:language/events',
view: () => m(eventList),
},
{
url: '/:language/events/:eventId',
view: vnode => m(eventDetails, vnode.attrs),
},
{
url: '/:language/jobs',
view: () => m(jobOfferList),
},
{
url: '/:language/jobs/:jobId',
view: vnode => m(jobOfferDetails, vnode.attrs),
},
{
url: '/:language/companies',
view: () => m(companyList),
},
{
url: '/:language/companies/:companyId',
view: vnode => m(companyDetail, vnode.attrs),
},
];
function onmatch(args, route) {
if (isLanguageValid(args.language)) {
changeLanguage(args.language);
return { view: vnode => m(layout, route.view(vnode)) };
if (verbose !== true) {
// set to pathname strategy (Please note that the production server needs to support this)
m.route.prefix('');
}
return {
view() {
return m(layout, m(Error404));
// routes which require authentication
const routesAuth = [
{
url: '/:language/studydocuments',
view: () => m(studydocList),
},
{
url: '/:language/studydocuments/new',
view: () => m(studydocNew),
},
};
}
{
url: '/:language/profile',
view: vnode => m(profile, vnode.attrs),
},
];
function generateRoutes() {
const result = {
'/': {
onmatch() {
m.route.set(`/${currentLanguage()}/`);
},
// routes without restrictions
const routes = [
{
url: '/:language',
view: () => m(amivLayout, m(frontpage)),
},
{
url: '/:language/amiv/statutes',
view: () => m(amivLayout, m(statutes)),
},
{
url: '/:language/amiv/board',
view: () => m(amivLayout, m(board)),
},
{
url: '/:language/amiv/commissions',
view: () => m(amivLayout, m(commissions)),
},
{
url: '/:language/amiv/about',
view: () => m(amivLayout, m(about)),
},
{
url: '/:language/contact',
view: () => m(contact),
},
{
url: '/:language/login',
view: () => m(login),
},
{
url: '/:language/logout',
view: () => m(logout),
},
};
{
url: '/:language/events',
view: () => m(eventList),
},
{
url: '/:language/events/:eventId',
view: vnode => m(eventDetails, vnode.attrs),
},
{
url: '/:language/jobs',
view: () => m(jobOfferList),
},
{
url: '/:language/jobs/:jobId',
view: vnode => m(jobOfferDetails, vnode.attrs),
},
{
url: '/:language/companies',
view: () => m(companyList),
},
{
url: '/:language/companies/:companyId',
view: vnode => m(companyDetail, vnode.attrs),
},
];
routes.forEach(r => {
result[r.url] = {
onmatch: args => onmatch(args, r),
function onmatch(args, route) {
if (isLanguageValid(args.language)) {
changeLanguage(args.language);
return { view: vnode => m(layout, route.view(vnode)) };
}
return {
view() {
return m(layout, m(Error404));
},
};
});
routesAuth.forEach(r => {
result[r.url] = {
onmatch(args) {
if (!isLoggedIn()) {
// m.route.set(`/${currentLanguage()}/login`);
return {
view() {
return m(layout, m(Error401));
},
};
}
}
return onmatch(args, r);
function generateRoutes() {
const result = {
'/': {
onmatch() {
m.route.set(`/${currentLanguage()}/`);
},
},
};
});
m.route(document.body, '/', result);
}
routes.forEach(r => {
result[r.url] = {
onmatch: args => onmatch(args, r),
};
});
routesAuth.forEach(r => {
result[r.url] = {
onmatch(args) {
if (!isLoggedIn()) {
// m.route.set(`/${currentLanguage()}/login`);
return {
view() {
return m(layout, m(Error401));
},
};
}
return onmatch(args, r);
},
};
});
m.route(document.body, '/', result);
}
generateRoutes();
generateRoutes();
});
......@@ -7,3 +7,8 @@ export const apiUrl = 'https://api-dev.amiv.ethz.ch';
* Enable/Disable verbose output.
*/
export const verbose = true;
/**
* Url used to send error logs
*/
export const sentryUrl = 'https://13e4a08420af47b3b4c2e9fe3442bfd8@sentry.amiv.ethz.ch/4';
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment