mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-10 04:22:12 +00:00
[now dev] Tests for routing and apply default frontend builder last (#2518)
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
5
test/fixtures/unit/now-dev-default-frontend/package.json
vendored
Normal file
5
test/fixtures/unit/now-dev-default-frontend/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"scripts": {
|
||||||
|
"build": "rm -Rf dist && cp -r public dist"
|
||||||
|
}
|
||||||
|
}
|
||||||
9
test/fixtures/unit/now-dev-default-frontend/public/index.html
vendored
Normal file
9
test/fixtures/unit/now-dev-default-frontend/public/index.html
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Hello World</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
Hello World
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
3
test/fixtures/unit/now-dev-default-routing/api/[endpoint].js
vendored
Normal file
3
test/fixtures/unit/now-dev-default-routing/api/[endpoint].js
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res) => {
|
||||||
|
res.end(`${req.query.endpoint}`);
|
||||||
|
};
|
||||||
3
test/fixtures/unit/now-dev-default-routing/api/[endpoint]/[id].js
vendored
Normal file
3
test/fixtures/unit/now-dev-default-routing/api/[endpoint]/[id].js
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res) => {
|
||||||
|
res.end(`${req.query.endpoint}/${req.query.id}`);
|
||||||
|
};
|
||||||
3
test/fixtures/unit/now-dev-default-routing/api/welcome.js
vendored
Normal file
3
test/fixtures/unit/now-dev-default-routing/api/welcome.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res) => {
|
||||||
|
res.end('hello and welcome');
|
||||||
|
};
|
||||||
5
test/fixtures/unit/now-dev-default-routing/package.json
vendored
Normal file
5
test/fixtures/unit/now-dev-default-routing/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"scripts": {
|
||||||
|
"build": "rm -Rf dist && cp -r public dist"
|
||||||
|
}
|
||||||
|
}
|
||||||
9
test/fixtures/unit/now-dev-default-routing/public/index.html
vendored
Normal file
9
test/fixtures/unit/now-dev-default-routing/public/index.html
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Hello World</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
Hello World
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user