Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CORS plugin to modular serve #2427

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/polite-adults-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'modular-scripts': patch
---

Allow assets served locally via `modular serve` to be loaded cross-domain via
the cors plugin
2 changes: 2 additions & 0 deletions packages/modular-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"chalk": "4.1.2",
"change-case": "4.1.2",
"commander": "9.4.0",
"cors": "^2.8.5",
"cosmiconfig": "^8.0.0",
"cross-spawn": "7.0.3",
"css-loader": "6.7.1",
Expand Down Expand Up @@ -161,6 +162,7 @@
"@modular-scripts/modular-types": "1.2.1",
"@schemastore/package": "0.0.6",
"@schemastore/tsconfig": "0.0.9",
"@types/cors": "^2.8.13",
"@types/js-yaml": "^4.0.5",
"@types/loader-utils": "^2.0.3",
"@types/validate-npm-package-name": "^4.0.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/modular-scripts/src/serve.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express from 'express';
import * as fs from 'fs-extra';
import cors from 'cors';
import determineTargetPaths from './build-scripts/common-scripts/determineTargetPaths';
import actionPreflightCheck from './utils/actionPreflightCheck';
import getWorkspaceLocation from './utils/getLocation';
Expand All @@ -17,6 +18,7 @@ async function serve(target: string, port = 3000): Promise<void> {

if (fs.existsSync(paths.appBuild)) {
const app = express();
app.use(cors());
app.use(express.static(paths.appBuild));
app.listen(port, () => {
logger.log(`Serving ${target} on ${port}`);
Expand Down
19 changes: 17 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2833,6 +2833,13 @@
dependencies:
"@types/node" "*"

"@types/cors@^2.8.13":
version "2.8.13"
resolved "https://registry.yarnpkg.com/@types/cors/-/cors-2.8.13.tgz#b8ade22ba455a1b8cb3b5d3f35910fd204f84f94"
integrity sha512-RG8AStHlUiV5ysZQKq97copd2UmVYw3/pRMLefISZ3S1hK104Cwm7iLQ3fTKx+lsUH2CE8FlLaYeEA2LSeqYUA==
dependencies:
"@types/node" "*"

"@types/cross-spawn@^6.0.2":
version "6.0.2"
resolved "https://registry.npmjs.org/@types/cross-spawn/-/cross-spawn-6.0.2.tgz"
Expand Down Expand Up @@ -4961,6 +4968,14 @@ core-util-is@~1.0.0:
resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz"
integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==

cors@^2.8.5:
version "2.8.5"
resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29"
integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==
dependencies:
object-assign "^4"
vary "^1"

cosmiconfig@^7.0.0, cosmiconfig@^7.0.1:
version "7.1.0"
resolved "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.1.0.tgz"
Expand Down Expand Up @@ -9180,7 +9195,7 @@ nwsapi@^2.2.2:
resolved "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.2.tgz"
integrity sha512-90yv+6538zuvUMnN+zCr8LuV6bPFdq50304114vJYJ8RDyK8D5O9Phpbd6SZWgI7PwzmmfN1upeOJlvybDSgCw==

object-assign@^4.1.0, object-assign@^4.1.1:
object-assign@^4, object-assign@^4.1.0, object-assign@^4.1.1:
version "4.1.1"
resolved "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz"
integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==
Expand Down Expand Up @@ -12330,7 +12345,7 @@ validate-npm-package-name@^5.0.0:
dependencies:
builtins "^5.0.0"

vary@~1.1.2:
vary@^1, vary@~1.1.2:
version "1.1.2"
resolved "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz"
integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==
Expand Down