This repository has been archived by the owner on May 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.js
77 lines (70 loc) · 2.34 KB
/
next.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
// next.config.js
// https://nextjs.org/docs/api-reference/next.config.js/introduction
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const Ajv = require('ajv').default;
const readYamlConfig = (configPath, schemaPath) => {
try {
const schema = JSON.parse(fs.readFileSync(schemaPath, 'utf8'));
const ajv = new Ajv({ useDefaults: true, removeAdditional: true });
const validate = ajv.compile(schema);
const data = yaml.load(fs.readFileSync(configPath, 'utf8'));
// Validation modifies the configuration data by adding defaults and
// removing additional properties.
validate(data);
return data;
} catch (err) {
console.error(`Configuration (${configPath}) could not be read.`, err);
process.exit(1);
}
};
const readPublicYamlConfig = () => {
const p = process.env.TS_CONFIG_PATH || 'times-square.config.yaml';
const configPath = path.isAbsolute(p) ? p : path.join(process.cwd(), p);
console.log(`Reading public Times Square config from ${configPath}`);
const schemaPath = path.join(__dirname, 'times-square.config.schema.json');
const data = readYamlConfig(configPath, schemaPath);
return data;
};
module.exports = (phase, { defaultConfig }) => {
const publicYamlConfig = readPublicYamlConfig();
const basePath = '/times-square';
const config = {
...defaultConfig,
basePath,
publicRuntimeConfig: {
...publicYamlConfig,
basePath,
},
// experimental: {
// // https://nextjs.org/docs/advanced-features/output-file-tracing
// outputStandalone: true,
// },
async rewrites() {
// For both the source and destination, don't include the basePath
// prefix for internal (same host) paths; next will apply it
// automatically.
return [
{
source: '/api/v1/pages',
destination: '/api/dev/times-square/v1/pages',
},
{
source: '/api/v1/pages/:page/html',
destination: '/api/dev/times-square/v1/pages/:page/html',
},
{
source: '/api/v1/pages/:page/htmlstatus',
destination: '/api/dev/times-square/v1/pages/:page/htmlstatus',
},
{
source: '/api/v1/pages/:page',
destination: '/api/dev/times-square/v1/pages/:page',
},
];
},
};
console.log(config);
return config;
};