-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
179 lines (159 loc) · 4.69 KB
/
vue.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
const { iterateProjects, getProjectPaths } = require('./apollo-server/utils/iterate_projects')
const path = require('path');
const fs = require('fs')
const os = require('os')
const _ = require('lodash')
const mkdirp = require('mkdirp')
// this alias is used by code copied from gitlab
const alias = {
'oc': path.join(__dirname, 'src/assets/javascripts'),
'oc_dashboard': path.join(__dirname, 'src/gitlab-oc/dashboard'),
'oc_vue_shared': path.join(__dirname, 'src/gitlab-oc/vue_shared'),
'~': path.join(__dirname, 'src/assets/javascripts'),
'oc_pages': path.join(__dirname, 'src/gitlab-oc')
//'oc': path.join(__dirname, 'src/gitlab-oc')
}
const httpProxyMiddleware = require('http-proxy-middleware');
const unfurlCloudBaseUrl = process.env.UNFURL_CLOUD_BASE_URL || ""
const username = process.env.UNFURL_CLOUD_USERNAME || "demo"
const fullname = process.env.UNFURL_CLOUD_FULLNAME || "Unfurl Cloud Craftsman"
// TODO fix this
const projectPath = `${username}/dashboard`
const projectPages = {}
const unfurlGUIBase = {unfurlCloudBaseUrl, username, fullname, projectPath}
const projectPageBase = {
entry: "src/pages/project_overview/index.js",
template: 'public/demo.html',
...unfurlGUIBase
}
const demoTemplate = _.template(fs.readFileSync(path.join(__dirname, 'public', 'demo.html'), 'utf-8'))
for(const {projectPath, blueprint} of iterateProjects()) {
if(projectPath != 'testing/simple-blueprint') continue
projectPages[projectPath] = {...projectPageBase, projectPath}
}
module.exports = {
devServer: {
onListening(devServer) {
const tmpDir = path.join(os.tmpdir(), '.unfurl-gui')
function setPid(program, pid) {
mkdirp.sync(tmpDir)
return fs.writeFileSync(path.join(tmpDir, `${program}.pid`), pid.toString())
}
setPid('serve', process.pid)
},
disableHostCheck: true,
before(app) {
const graphqlProxy = httpProxyMiddleware('/graphql', {
target: 'http://localhost:4000/graphql',
changeOrigin: true,
ws: true,
ignorePath: true,
protocolRewrite: process.env.SSL_PROXY,
})
// patterns can't be used unless they're all patterns
const expressProxy = httpProxyMiddleware([
'/proxied/**',
'/*/dashboard/-/variables',
'/*/unfurl-types/-/raw/*/icons/*'
], {
target: 'http://localhost:4000',
changeOrigin: true,
ws: true,
protocolRewrite: process.env.SSL_PROXY,
})
const postProxy = httpProxyMiddleware(
function (_, req) {
return req.method == 'POST'
},
{
target: 'http://localhost:4000',
changeOrigin: true,
protocolRewrite: process.env.SSL_PROXY
}
)
// try to send the blueprint pages even if they're not in webpack entries yet
app.use((req, res, next) => {
if(req.method != 'GET') {
next(); return
}
const projectPaths = getProjectPaths()
const normalizedPath = req.url.split('/').filter(s => s).join('/')
let matchingPath
if(!(matchingPath = projectPaths.find(path => normalizedPath.startsWith(path)))) {
next(); return
}
const templateParameters = {
htmlWebpackPlugin: {
options: {...projectPageBase, projectPath: matchingPath, inject: true}
}
}
res.send( demoTemplate(templateParameters) )
})
app.use(graphqlProxy)
app.use(expressProxy)
app.use(postProxy)
},
},
pluginOptions: {
apollo: {
enableMocks: false,
enableEngine: true,
lintGQL: true
}
},
configureWebpack: {
resolve: {
alias,
symlinks: false
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
'eslint-loader',
'webpack-preprocessor-loader',
]
},
{
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true
}
}
]
}
],
}
},
pages: {
index: {
entry: "src/main.ts",
template: 'public/index.html',
...unfurlGUIBase
},
demo: {
...projectPageBase,
entry: "src/pages/project_overview/index.js",
template: 'public/demo.html',
unfurlCloudBaseUrl
},
...projectPages,
dashboard: {
title: "Unfurl Cloud Dashboard",
entry: "src/pages/dashboard/index.js",
unfurlCloudBaseUrl,
...unfurlGUIBase
},
form: {
title: "Formily Testbed",
entry: "src/pages/form/main.ts",
template: 'public/form.html',
unfurlCloudBaseUrl
}
}
};