-
Notifications
You must be signed in to change notification settings - Fork 2
/
web-dev-server.config.mjs
58 lines (52 loc) · 1.62 KB
/
web-dev-server.config.mjs
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
import proxy from 'koa-proxies';
import getPort from 'get-port';
import { OAuth2Server } from 'oauth2-mock-server';
import { AuthProxy } from './demo/AuthProxy.mjs';
/** @typedef {import('@web/dev-server').DevServerConfig} DevServerConfig */
const oauth2server = new OAuth2Server();
const authProxy = new AuthProxy();
let oauth2env;
/* eslint-disable consistent-return */
export default /** @type DevServerConfig */ ({
// http2: true,
// sslKey: 'demo/private.key',
// sslCert: 'demo/private.pem',
plugins: [
{
name: 'auth',
async serverStart({ app }) {
const port = await getPort({ port: getPort.makeRange(8000, 8100) });
const proxyPort = await getPort({ port: getPort.makeRange(8000, 8100) });
app.use(
proxy('/auth', {
target: `http://localhost:${port}`,
// logs: true,
rewrite: path => path.replace('/auth', ''),
}),
);
const jwtKey = await oauth2server.issuer.keys.generateRSA();
await oauth2server.start(port, 'localhost');
await authProxy.start(proxyPort);
oauth2env = {
port,
root: '/auth',
jwtKey,
issuer: oauth2server.issuer.url,
tokenProxy: `http://localhost:${proxyPort}/proxy?u=`
};
},
async serverStop() {
await oauth2server.stop();
await authProxy.stop();
},
serve(context) {
if (context.path === '/demo/env.js') {
const data = {
oauth2: oauth2env,
};
return `export default ${JSON.stringify(data)}`;
}
},
},
],
});