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

[3.0] Changes WebApp to use Express under the hood #12442

Merged
merged 25 commits into from Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
be725b8
chore: added express instead of connect
Grubba27 Jan 13, 2023
d427749
docs: added history about changes in webapp
Grubba27 Jan 13, 2023
08e91e7
docs: changes rawConnectHandlers by rawExpressHandlers
Grubba27 Jan 13, 2023
91af432
docs: changes connect by express in security.md
Grubba27 Jan 13, 2023
2fe9d36
docs: changes connect docs by express docs
Grubba27 Jan 13, 2023
3609a65
chore: changes appcache-server.js connect by express
Grubba27 Jan 13, 2023
dd223a8
chore: update browser-policy-common to use rawExpressHandlers
Grubba27 Jan 13, 2023
8ec1f6b
chore: update test_responder to use express
Grubba27 Jan 13, 2023
44547aa
chore: spiderable_server is now using express
Grubba27 Jan 13, 2023
ad76faf
chore: updated oauth_server to use expressHandler
Grubba27 Jan 13, 2023
80a274b
chore: added packages in lock file
Grubba27 Jan 13, 2023
d233c04
chore: removed connect.js file
Grubba27 Jan 13, 2023
929da0d
chore: remove connect from webapp
Grubba27 Jan 13, 2023
f2f2c4e
docs: updated webapp readme
Grubba27 Jan 13, 2023
62066ac
types: updated webapp types
Grubba27 Jan 13, 2023
7cd854b
chore: update apollo skeleton with new express app
Grubba27 Jan 13, 2023
560c1b3
feat: added express to webserver
Grubba27 Jan 13, 2023
ae3e31f
tests: adjusted test to match express npm modules
Grubba27 Jan 13, 2023
2b91f52
Update packages/webapp/webapp.d.ts
Grubba27 Jan 16, 2023
8296afc
chore: addressed security comments
Grubba27 Jan 16, 2023
e4a3fb5
chore: add raw handlers
Grubba27 Jan 16, 2023
829bf9f
types: adressed wrong typings
Grubba27 Jan 18, 2023
1b921ec
chore: created abstraction on top of express creation
Grubba27 Jan 18, 2023
1d3cfca
updated last express method
Grubba27 Jan 18, 2023
e5e23fb
Merge branch 'release-3.0' into release-3.0-tests-webapp
Grubba27 Jan 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/history.md
Expand Up @@ -69,7 +69,11 @@

* `webapp`:
- `WebAppInternals.getBoilerplate` is now async.

- Changed engine from connect to express and changed api naming to match express. See below:
- `WebApp.connectHandlers.use(middleware)` is now `WebApp.expressHandlers.use(middleware)`
- `WebApp.rawConnectHandlers.use(middleware)` is now `WebApp.rawExpressHandlers.use(middleware)`
- `WebApp.connectApp` is now `WebApp.expressApp`

#### Internal API changes


Expand Down
14 changes: 7 additions & 7 deletions docs/source/packages/webapp.md
Expand Up @@ -13,20 +13,20 @@ This package also allows you to add handlers for HTTP requests.
This lets other services access your app's data through an HTTP API, allowing
it to easily interoperate with tools and frameworks that don't yet support DDP.

`webapp` exposes the [connect](https://github.com/senchalabs/connect) API for
handling requests through `WebApp.connectHandlers`.
`webapp` exposes the [express](https://github.com/expressjs/express) API for
handling requests through `WebApp.expressHandlers`.
Here's an example that will let you handle a specific URL:

```js
// Listen to incoming HTTP requests (can only be used on the server).
WebApp.connectHandlers.use('/hello', (req, res, next) => {
WebApp.expressHandlers.use('/hello', (req, res, next) => {
res.writeHead(200);
res.end(`Hello world from: ${Meteor.release}`);
});
```

{% apibox "WebApp.connectHandlers" %}
{% apibox "connectHandlersCallback(req, res, next)" %}
{% apibox "WebApp.expressHandlers" %}
{% apibox "expressHandlersCallback(req, res, next)" %}

### Serving a Static Landing Page

Expand Down Expand Up @@ -62,14 +62,14 @@ Here's a sample _index.html_ you might use to get started:
</html>
```

Then using the connectHandlers method described above serve up your static HTML on app-root/ page load as shown below.
Then using the expressHandlers method described above serve up your static HTML on app-root/ page load as shown below.

```
/* global WebApp Assets */
import crypto from 'crypto'
import connectRoute from 'connect-route'

WebApp.connectHandlers.use(connectRoute(function (router) {
WebApp.expressHandlers.use(connectRoute(function (router) {
router.get('/', function (req, res, next) {
const buf = Assets.getText('index.html')

Expand Down
2 changes: 1 addition & 1 deletion guide/source/deployment.md
Expand Up @@ -99,7 +99,7 @@ If you are hosting a webfont as part of your application and serving it via a CD
```js
import { WebApp } from 'meteor/webapp';

WebApp.rawConnectHandlers.use(function(req, res, next) {
WebApp.rawExpressHandlers.use(function(req, res, next) {
if (req._parsedUrl.pathname.match(/\.(ttf|ttc|otf|eot|woff|woff2|font\.css|css)$/)) {
res.setHeader('Access-Control-Allow-Origin', /* your hostname, or just '*' */);
}
Expand Down
6 changes: 3 additions & 3 deletions guide/source/security.md
Expand Up @@ -480,7 +480,7 @@ By default, Helmet can be used to set various HTTP headers (see link above). The
import helmet from "helmet";

// Within server side Meter.startup()
WebApp.connectHandlers.use(helmet())
WebApp.expressHandlers.use(helmet())
```

At a minimum, Meteor recommends users to set the following headers. Note that code examples shown below are specific to Helmet.
Expand All @@ -500,7 +500,7 @@ By default, Meteor recommends unsafe inline scripts and styles are allowed, sinc
import helmet from "helmet";

// Within server side Meter.startup()
WebApp.connectHandlers.use(
WebApp.expressHandlers.use(
helmet.contentSecurityPolicy({
directives: {
defaultSrc: ["'self'"],
Expand Down Expand Up @@ -679,7 +679,7 @@ With Helmet, Frameguard sets the X-Frame-Options header.
import helmet from "helmet";

// Within server side Meter.startup()
WebApp.connectHandlers.use(helmet.frameguard()); // defaults to sameorigin
WebApp.expressHandlers.use(helmet.frameguard()); // defaults to sameorigin
```
For more detail please read the following guide: [Frameguard](https://helmetjs.github.io/docs/frameguard/).

Expand Down
2 changes: 1 addition & 1 deletion packages/appcache/appcache-server.js
Expand Up @@ -63,7 +63,7 @@ WebApp.addHtmlAttributeHook(request =>
{ manifest: "/app.manifest" }
);

WebApp.connectHandlers.use((req, res, next) => {
WebApp.expressHandlers.use((req, res, next) => {
if (req.url !== '/app.manifest') {
return next();
}
Expand Down
8 changes: 4 additions & 4 deletions packages/browser-policy-common/browser-policy-common.js
Expand Up @@ -10,7 +10,7 @@ BrowserPolicy._setRunningTest = function () {
inTest = true;
};

WebApp.connectHandlers.use(function (req, res, next) {
WebApp.expressHandlers.use(function (req, res, next) {
// Never set headers inside tests because they could break other tests.
if (BrowserPolicy._runningTest())
return next();
Expand All @@ -28,13 +28,13 @@ WebApp.connectHandlers.use(function (req, res, next) {
next();
});

// We use `rawConnectHandlers` to set X-Content-Type-Options on all
// We use `rawExpressHandlers` to set X-Content-Type-Options on all
// requests, including static files.
// XXX We should probably use `rawConnectHandlers` for X-Frame-Options
// XXX We should probably use `rawExpressHandlers` for X-Frame-Options
// and Content-Security-Policy too, but let's make sure that doesn't
// break anything first (e.g. the OAuth popup flow won't work well with
// a CSP that disallows inline scripts).
WebApp.rawConnectHandlers.use(function (req, res, next) {
WebApp.rawExpressHandlers.use(function (req, res, next) {
if (BrowserPolicy._runningTest())
return next();

Expand Down
2 changes: 1 addition & 1 deletion packages/deprecated/http/test_responder.js
Expand Up @@ -76,7 +76,7 @@ var respond = function(req, res) {
};

var run_responder = function() {
WebApp.connectHandlers.stack.unshift(
WebApp.expressHandlers.stack.unshift(
{ route: TEST_RESPONDER_ROUTE, handle: respond });
};

Expand Down
2 changes: 1 addition & 1 deletion packages/deprecated/spiderable/spiderable_server.js
Expand Up @@ -58,7 +58,7 @@ Spiderable._urlForPhantom = function (siteAbsoluteUrl, requestUrl) {

var PHANTOM_SCRIPT = Assets.getText("phantom_script.js");

WebApp.connectHandlers.use(function (req, res, next) {
WebApp.expressHandlers.use(function (req, res, next) {
// _escaped_fragment_ comes from Google's AJAX crawling spec:
// https://developers.google.com/webmasters/ajax-crawling/docs/specification
if (/\?.*_escaped_fragment_=/.test(req.url) ||
Expand Down
6 changes: 3 additions & 3 deletions packages/oauth/oauth_server.js
Expand Up @@ -205,9 +205,9 @@ const middleware = async (req, res, next) => {
};

// Listen to incoming OAuth http requests
WebApp.connectHandlers.use('/_oauth', bodyParser.json());
WebApp.connectHandlers.use('/_oauth', bodyParser.urlencoded({ extended: false }));
WebApp.connectHandlers.use(middleware);
WebApp.expressHandlers.use('/_oauth', bodyParser.json());
WebApp.expressHandlers.use('/_oauth', bodyParser.urlencoded({ extended: false }));
WebApp.expressHandlers.use(middleware);

OAuthTest.middleware = middleware;

Expand Down