This repository has been archived by the owner on Jan 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnuxt.config.js
126 lines (119 loc) · 3.45 KB
/
nuxt.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Use .env in nuxt config only (keep secrets on the dl)
// -- https://github.com/nuxt/nuxt.js/issues/2033#issuecomment-398820574
// -- https://github.com/nuxt-community/dotenv-module#using-env-file-in-nuxtconfigjs
import 'dotenv/config'
// Body parser middleware needed to inject required fields for LibCal API auth
import bodyParser from 'body-parser'
const labstatsApi = 'https://online.labstats.com'
const labstatsApiPath = '/api/labstats/'
const libcalApi = 'https://api2.libcal.com'
const libcalApiPath = '/api/libcal/'
const libcalHoursApi = 'https://api3.libcal.com'
const libcalHoursApiPath = '/api/libcal-hours/'
const r25Api = 'https://r25.registrar.cornell.edu/r25ws/servlet/wrd/run'
const r25ApiPath = '/api/r25/'
var restreamClientCreds = (proxyReq, req, res) => {
if (req.method === 'POST' && req.body) {
// Build object for POST request to obtain access token
let body = {
client_id: process.env.LIBCAL_CLIENT_ID,
client_secret: process.env.LIBCAL_CLIENT_SECRET,
grant_type: 'client_credentials'
}
body = JSON.stringify(body)
// Update headers
proxyReq.setHeader('Content-Type', 'application/json')
proxyReq.setHeader('Content-Length', Buffer.byteLength(body))
// Write new body to the proxyReq stream
proxyReq.write(body)
}
}
module.exports = {
modules: [
'@nuxtjs/axios'
],
serverMiddleware: [
// Parse request body so it can be manipulated by proxy middleware
// -- https://nuxtjs.org/api/configuration-servermiddleware
{ path: libcalApiPath, handler: bodyParser.json() }
],
axios: {
prefix: '/api/',
proxy: true
},
proxy: {
[labstatsApiPath]: {
target: labstatsApi,
pathRewrite: { [`^${labstatsApiPath}`]: '' },
onProxyReq: (proxyReq, req, res) => {
// Auth header
proxyReq.setHeader('Authorization', process.env.LABSTATS_AUTH)
}
},
[libcalApiPath]: {
target: libcalApi,
pathRewrite: { [`^${libcalApiPath}`]: '' },
onProxyReq: restreamClientCreds
},
[libcalHoursApiPath]: {
target: libcalHoursApi,
pathRewrite: { [`^${libcalHoursApiPath}`]: '' }
},
[r25ApiPath]: {
target: r25Api,
pathRewrite: { [`^${r25ApiPath}`]: '' },
onProxyReq: (proxyReq, req, res) => {
// Auth header
proxyReq.setHeader('Authorization', process.env.R25_AUTH)
}
}
},
/*
** Headers of the page
*/
head: {
title: 'CUL Signage',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: 'Nuxt.js project' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
{ rel: 'stylesheet', href: 'https://fonts.googleapis.com/css?family=Montserrat:400,500,600,700' }
]
},
/*
** Customize the progress-bar color
*/
loading: { color: 'rgba(33,43,57,.3)' },
/*
** Build configuration
*/
build: {
loaders: {
vue: {
compilerOptions: {
whitespace: 'condense'
}
}
},
/*
** Run ESLINT on save
*/
extend (config, { isDev, isClient }) {
if (isDev && isClient) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
}, {
enforce: 'pre',
test: /\.js$/,
loader: 'source-map-loader'
})
}
}
}
}