[now dev] Tests for routing and apply default frontend builder last (#2518)

This commit is contained in:
Andy
2019-07-09 20:58:04 +02:00
committed by Andy Bitz
parent ee80ea59f4
commit 00c792297a
8 changed files with 53 additions and 12 deletions

View File

@@ -351,19 +351,7 @@ export default class DevServer {
const apiFiles = await getApiFiles(this.cwd, this.output); const apiFiles = await getApiFiles(this.cwd, this.output);
const hasNoBuilds = !config.builds || config.builds.length === 0; const hasNoBuilds = !config.builds || config.builds.length === 0;
if (pkg && hasNoBuilds) {
config.builds = config.builds || [];
const staticBuilder = await detectBuilder(pkg);
if (staticBuilder) {
config.builds.push(staticBuilder);
}
}
if (apiFiles.length > 0) { if (apiFiles.length > 0) {
// We need to use `hasNoBuilds` because it was created
// before `staticBuilder` was added
if (hasNoBuilds) { if (hasNoBuilds) {
const apiBuilds = await detectApiBuilders(apiFiles); const apiBuilds = await detectApiBuilders(apiFiles);
@@ -384,6 +372,22 @@ export default class DevServer {
} }
} }
/**
* We need to use `hasNoBuilds` because it was created
* before the api builders were added.
* We also have to add this builder after all
* the others to prevent catch all routes etc.
*/
if (pkg && hasNoBuilds) {
config.builds = config.builds || [];
const staticBuilder = await detectBuilder(pkg);
if (staticBuilder) {
config.builds.push(staticBuilder);
}
}
this.validateNowConfig(config); this.validateNowConfig(config);
this.cachedNowJson = config; this.cachedNowJson = config;
return config; return config;

View File

@@ -0,0 +1,5 @@
{
"scripts": {
"build": "rm -Rf dist && cp -r public dist"
}
}

View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
Hello World
</body>
</html>

View File

@@ -0,0 +1,3 @@
module.exports = (req, res) => {
res.end(`${req.query.endpoint}`);
};

View File

@@ -0,0 +1,3 @@
module.exports = (req, res) => {
res.end(`${req.query.endpoint}/${req.query.id}`);
};

View File

@@ -0,0 +1,3 @@
module.exports = (req, res) => {
res.end('hello and welcome');
};

View File

@@ -0,0 +1,5 @@
{
"scripts": {
"build": "rm -Rf dist && cp -r public dist"
}
}

View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
Hello World
</body>
</html>