Skip to content

Commit 9e68fa2

Browse files
github-actions[bot]create-or-update-pull-requestbjohansebas
authored
Update external docs (#1946)
update external docs Co-authored-by: Create or Update Pull Request Action <create-or-update-pull-request@users.noreply.github.com> Co-authored-by: Sebastian Beltran <bjohansebas@gmail.com>
1 parent 0f3d24c commit 9e68fa2

4 files changed

Lines changed: 80 additions & 87 deletions

File tree

_includes/readmes/cors.md

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ CORS is a node.js package for providing a [Connect](http://www.senchalabs.org/co
1616
* [Configuring CORS](#configuring-cors)
1717
* [Configuring CORS w/ Dynamic Origin](#configuring-cors-w-dynamic-origin)
1818
* [Enabling CORS Pre-Flight](#enabling-cors-pre-flight)
19-
* [Configuring CORS Asynchronously](#configuring-cors-asynchronously)
19+
* [Customizing CORS Settings Dynamically per Request](#customizing-cors-settings-dynamically-per-request)
2020
* [Configuration Options](#configuration-options)
2121
* [License](#license)
2222
* [Author](#author)
@@ -69,6 +69,8 @@ app.listen(80, function () {
6969

7070
### Configuring CORS
7171

72+
See the [configuration options](#configuration-options) for details.
73+
7274
```javascript
7375
var express = require('express')
7476
var cors = require('cors')
@@ -161,27 +163,45 @@ NOTE: When using this middleware as an application level middleware (for
161163
example, `app.use(cors())`), pre-flight requests are already handled for all
162164
routes.
163165

164-
### Configuring CORS Asynchronously
166+
### Customizing CORS Settings Dynamically per Request
165167

166-
```javascript
167-
var express = require('express')
168-
var cors = require('cors')
169-
var app = express()
168+
For APIs that require different CORS configurations for specific routes or requests, you can dynamically generate CORS options based on the incoming request. The `cors` middleware allows you to achieve this by passing a function instead of static options. This function is called for each incoming request and must use the callback pattern to return the appropriate CORS options.
169+
170+
The function accepts:
171+
1. **`req`**:
172+
- The incoming request object.
173+
174+
2. **`callback(error, corsOptions)`**:
175+
- A function used to return the computed CORS options.
176+
- **Arguments**:
177+
- **`error`**: Pass `null` if there’s no error, or an error object to indicate a failure.
178+
- **`corsOptions`**: An object specifying the CORS policy for the current request.
170179

171-
var allowlist = ['http://example1.com', 'http://example2.com']
172-
var corsOptionsDelegate = function (req, callback) {
180+
Here’s an example that handles both public routes and restricted, credential-sensitive routes:
181+
182+
```javascript
183+
var dynamicCorsOptions = function(req, callback) {
173184
var corsOptions;
174-
if (allowlist.indexOf(req.header('Origin')) !== -1) {
175-
corsOptions = { origin: true } // reflect (enable) the requested origin in the CORS response
185+
if (req.path.startsWith('/auth/connect/')) {
186+
corsOptions = {
187+
origin: 'http://mydomain.com', // Allow only a specific origin
188+
credentials: true, // Enable cookies and credentials
189+
};
176190
} else {
177-
corsOptions = { origin: false } // disable CORS for this request
191+
corsOptions = { origin: '*' }; // Allow all origins for other routes
178192
}
179-
callback(null, corsOptions) // callback expects two parameters: error and options
180-
}
193+
callback(null, corsOptions);
194+
};
181195

182-
app.get('/products/:id', cors(corsOptionsDelegate), function (req, res, next) {
183-
res.json({msg: 'This is CORS-enabled for an allowed domain.'})
184-
})
196+
app.use(cors(dynamicCorsOptions));
197+
198+
app.get('/auth/connect/twitter', function (req, res) {
199+
res.send('CORS dynamically applied for Twitter authentication.');
200+
});
201+
202+
app.get('/public', function (req, res) {
203+
res.send('Public data with open CORS.');
204+
});
185205

186206
app.listen(80, function () {
187207
console.log('CORS-enabled web server listening on port 80')
@@ -192,7 +212,9 @@ app.listen(80, function () {
192212

193213
* `origin`: Configures the **Access-Control-Allow-Origin** CORS header. Possible values:
194214
- `Boolean` - set `origin` to `true` to reflect the [request origin](http://tools.ietf.org/html/draft-abarth-origin-09), as defined by `req.header('Origin')`, or set it to `false` to disable CORS.
195-
- `String` - set `origin` to a specific origin. For example if you set it to `"http://example.com"` only requests from "http://example.com" will be allowed.
215+
- `String` - set `origin` to a specific origin. For example, if you set it to
216+
- `"http://example.com"` only requests from "http://example.com" will be allowed.
217+
- `"*"` for all domains to be allowed.
196218
- `RegExp` - set `origin` to a regular expression pattern which will be used to test the request origin. If it's a match, the request origin will be reflected. For example the pattern `/example\.com$/` will reflect any request that is coming from an origin ending with "example.com".
197219
- `Array` - set `origin` to an array of valid origins. Each origin can be a `String` or a `RegExp`. For example `["http://example1.com", /\.example2\.com$/]` will accept any request from "http://example1.com" or from a subdomain of "example2.com".
198220
- `Function` - set `origin` to a function implementing some custom logic. The function takes the request origin as the first parameter and a callback (called as `callback(err, origin)`, where `origin` is a non-function value of the `origin` option) as the second.

_includes/readmes/method-override.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ typically be used in conjunction with `XMLHttpRequest` on implementations
6767
that do not support the method you are trying to use.
6868

6969
```js
70-
var express = require('express')
71-
var methodOverride = require('method-override')
72-
var app = express()
70+
const express = require('express')
71+
const methodOverride = require('method-override')
72+
const app = express()
7373

7474
// override with the X-HTTP-Method-Override header in the request
7575
app.use(methodOverride('X-HTTP-Method-Override'))
@@ -80,7 +80,7 @@ Example call with header override using `XMLHttpRequest`:
8080
<!-- eslint-env browser -->
8181

8282
```js
83-
var xhr = new XMLHttpRequest()
83+
const xhr = new XMLHttpRequest()
8484
xhr.onload = onload
8585
xhr.open('post', '/resource', true)
8686
xhr.setRequestHeader('X-HTTP-Method-Override', 'DELETE')
@@ -102,9 +102,9 @@ query value would typically be used in conjunction with plain HTML
102102
newer methods.
103103

104104
```js
105-
var express = require('express')
106-
var methodOverride = require('method-override')
107-
var app = express()
105+
const express = require('express')
106+
const methodOverride = require('method-override')
107+
const app = express()
108108

109109
// override with POST having ?_method=DELETE
110110
app.use(methodOverride('_method'))
@@ -121,9 +121,9 @@ Example call with query override using HTML `<form>`:
121121
### multiple format support
122122

123123
```js
124-
var express = require('express')
125-
var methodOverride = require('method-override')
126-
var app = express()
124+
const express = require('express')
125+
const methodOverride = require('method-override')
126+
const app = express()
127127

128128
// override with different headers; last one takes precedence
129129
app.use(methodOverride('X-HTTP-Method')) // Microsoft
@@ -137,10 +137,10 @@ You can implement any kind of custom logic with a function for the `getter`. The
137137
implements the logic for looking in `req.body` that was in `method-override@1`:
138138

139139
```js
140-
var bodyParser = require('body-parser')
141-
var express = require('express')
142-
var methodOverride = require('method-override')
143-
var app = express()
140+
const bodyParser = require('body-parser')
141+
const express = require('express')
142+
const methodOverride = require('method-override')
143+
const app = express()
144144

145145
// NOTE: when using req.body, you must fully parse the request body
146146
// before you call methodOverride() in your middleware stack,
@@ -149,7 +149,7 @@ app.use(bodyParser.urlencoded())
149149
app.use(methodOverride(function (req, res) {
150150
if (req.body && typeof req.body === 'object' && '_method' in req.body) {
151151
// look in urlencoded POST bodies and delete it
152-
var method = req.body._method
152+
const method = req.body._method
153153
delete req.body._method
154154
return method
155155
}

_includes/readmes/serve-favicon.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
[![NPM Version][npm-image]][npm-url]
44
[![NPM Downloads][downloads-image]][downloads-url]
55
[![Linux Build Status][ci-image]][ci-url]
6-
[![Windows Build][appveyor-image]][appveyor-url]
76
[![Coverage Status][coveralls-image]][coveralls-url]
7+
[![OpenSSF Scorecard Badge][ossf-scorecard-badge]][ossf-scorecard-visualizer]
88

99
Node.js middleware for serving a favicon.
1010

@@ -124,8 +124,6 @@ server.listen(3000)
124124

125125
[MIT](LICENSE)
126126

127-
[appveyor-image]: https://img.shields.io/appveyor/ci/dougwilson/serve-favicon/master.svg?label=windows
128-
[appveyor-url]: https://ci.appveyor.com/project/dougwilson/serve-favicon
129127
[ci-image]: https://badgen.net/github/checks/expressjs/serve-favicon/master?label=ci
130128
[ci-url]: https://github.com/expressjs/serve-favicon/actions/workflows/ci.yml
131129
[coveralls-image]: https://img.shields.io/coveralls/expressjs/serve-favicon.svg
@@ -134,3 +132,5 @@ server.listen(3000)
134132
[downloads-url]: https://npmjs.org/package/serve-favicon
135133
[npm-image]: https://img.shields.io/npm/v/serve-favicon.svg
136134
[npm-url]: https://npmjs.org/package/serve-favicon
135+
[ossf-scorecard-badge]: https://api.scorecard.dev/projects/github.com/expressjs/serve-favicon/badge
136+
[ossf-scorecard-visualizer]: https://ossf.github.io/scorecard-visualizer/#/projects/github.com/expressjs/serve-favicon

en/resources/contributing.md

Lines changed: 23 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -339,38 +339,29 @@ pull request.
339339
<!-- LOCAL: expressjs/expressjs.com ../../CONTRIBUTING.md -->
340340
### The Official Documentation of the Express JS Framework
341341

342-
This is the contribution documentation for the [Expressjs.com](https://github.com/expressjs/expressjs.com) website.
342+
This is the contribution documentation for the [expressjs.com](https://github.com/expressjs/expressjs.com) website.
343343

344344

345345

346346
#### Need some ideas? These are some typical issues.
347347

348-
1. **Website issues**:
349-
If you see anything on the site that could use a tune-up, think about how to fix it.
350-
348+
1. **Website issues**: If you see anything on the site that could use a tune-up, think about how to fix it.
351349
- Display or screen sizing problems
352350
- Mobile responsiveness issues
353351
- Missing or broken accessibility features
354352
- Website outages
355353
- Broken links
356354
- Page structure or user interface enhancements
357355

358-
359-
2. **Content Issues**:
360-
Fix anything related to site content or typos.
356+
2. **Content Issues**: Fix anything related to site content or typos.
361357
- Spelling errors
362358
- Incorrect/outdated Express JS documentation
363359
- Missing content
364360

365-
366361
3. **Translation Issues**: Fix any translation errors or contribute new content.
367362
- Fix spelling errors
368363
- Fix incorrect/poorly translated words
369-
- Translate new content
370-
> **IMPORTANT:**
371-
> All translation submissions are currently paused. See this [notice](#notice-we-have-paused-all-translation-contributions) for more information.
372-
373-
- Check out the [Contributing translations](#contributing-translations) section below for a contributing guide.
364+
- Check out the [Contributing translations](#contributing-translations) section below for a contributing guide.
374365

375366
#### Want to work on a backlog issue?
376367

@@ -380,6 +371,7 @@ We often have bugs or enhancements that need work. You can find these under our
380371

381372
If you've found a bug or a typo, or if you have an idea for an enhancement, you can:
382373
- Submit a [new issue](https://github.com/expressjs/expressjs.com/issues/new/choose) on our repo. Do this for larger proposals, or if you'd like to discuss or get feedback first.
374+
383375
- Make a [Github pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request). If you have already done work and it's ready to go, feel free to send it our way.
384376

385377
## Getting Started
@@ -400,7 +392,9 @@ So you've found a problem that you want to fix, or have a site enhancement you w
400392

401393
Clone the repo and get the code:
402394

403-
git clone https://github.com/expressjs/expressjs.com.git
395+
```sh
396+
git clone https://github.com/expressjs/expressjs.com.git
397+
```
404398

405399
After you've got the code you're ready to start making your changes!
406400

@@ -426,64 +420,41 @@ follow the specific instructions for [How to write a blog post.](https://express
426420
**CSS or Javascript**
427421
- All css and js files are kept in `css` and `js` folders on the project root.
428422

429-
The Express JS website is build using [Jeykyll](https://jekyllrb.com/) and is hosted on [Github Pages](https://pages.github.com/).
423+
The Express JS website is built using [Jekyll](https://jekyllrb.com/) and is hosted on [Github Pages](https://pages.github.com/).
430424

431425
#### Step 3: Running the Application
432426

433-
434427
Now you'll need a way to see your changes, which means you'll need a running version of the application. You have two options.
435-
1. __Run Locally__: This gets the local version of the application up and running on your machine. Follow our [Local Setup Guide](https://github.com/expressjs/expressjs.com?tab=readme-ov-file#local-setup) to use this option.
428+
429+
430+
1. __Run Locally__: This gets the local version of the application up and running on your machine. Follow our [Local Setup Guide](https://github.com/expressjs/expressjs.com?tab=readme-ov-file#build-the-website-locally) to use this option.
436431
- This is the recommended option for moderate to complex work.
432+
437433
2. __Run using Deploy Preview__: Use this option if you don't want to bother with a local installation. Part of our continuous integration pipeline includes [Netlify Deploy Preview](https://docs.netlify.com/site-deploys/deploy-previews/).
438434
1. To use this you'll need to get your changes online - after you've made your first commit on your feature branch, make a *draft* pull request.
439435
2. After the build steps are complete, you'll have access to a __Deploy Preview__ tab that will run your changes on the web, rebuilding after each commit is pushed.
440436
3. After you are completely done your work and it's ready for review, remove the draft status on your pull request and submit your work.
441437

442438
## Contributing translations
443439

444-
#### Notice: We have paused all translation contributions.
445-
> **IMPORTANT:**
446-
> We are currently working toward a more streamlined translations workflow. As long as this notice is posted, we will _not_ be accepting any translation submissions.
447-
448-
We highly encourage community translations! We no longer have professional translations, and we believe in the power of our community to provide accurate and helpful translations.
440+
We use Crowdin to manage our translations in multiple languages and achieve automatic translation with artificial intelligence. Since these translations can be inefficient in some cases, we need help from the community to provide accurate and helpful translations.
449441

450442
The documentation is translated into these languages:
443+
444+
- Chinese Simplified (`zh-cn`)
445+
- Chinese Traditional (`zh-tw`)
451446
- English (`en`)
452-
- Spanish (`es`)
453447
- French (`fr`)
448+
- German (`de`)
454449
- Italian (`it`)
455-
- Indonesian (`id`)
456450
- Japanese (`ja`)
457451
- Korean (`ko`)
458452
- Brazilian Portuguese (`pt-br`)
459-
- Russian (`ru`)
460-
- Slovak (`sk`)
461-
- Thai (`th`)
462-
- Turkish (`tr`)
463-
- Ukrainian (`uk`)
464-
- Uzbek (`uz`)
465-
- Simplified Chinese (`zh-cn`)
466-
- Traditional Chinese (`zh-tw`)
467-
468-
### Adding New Full Site Translations
469-
470-
If you find a translation is missing from the list you can create a new one.
471-
472-
To translate Expressjs.com into a new language, follow these steps:
473-
474-
1. Clone the [`expressjs.com`](https://github.com/expressjs/expressjs.com) repository.
475-
2. Create a directory for the language of your choice using its [ISO 639-1 code](https://www.loc.gov/standards/iso639-2/php/code_list.php) as its name.
476-
3. Copy `index.md`, `api.md`, `starter/`, `guide/`, `advanced/`, `resources/`, `4x/`, and `3x/`, to the language directory.
477-
4. Remove the link to 2.x docs from the "API Reference" menu.
478-
5. Update the `lang` variable in the copied markdown files.
479-
6. Update the `title` variable in the copied markdown files.
480-
7. Create the header, footer, notice, and announcement file for the language in the `_includes/` directory, in the respective directories, and make necessary edits to the contents.
481-
8. Create the announcement file for the language in the `_includes/` directory.
482-
9. Make sure to append `/{{ page.lang }}` to all the links within the site.
483-
10. Update the [CONTRIBUTING.md](https://github.com/expressjs/expressjs.com/blob/gh-pages/CONTRIBUTING.md#contributing-translations) and the `.github/workflows/translation.yml` files with the new language.
453+
- Spanish (`es`)
484454

485-
### Adding Page and Section Translations
455+
### How to translate
486456

487-
Many site translations are still missing pages. To find which ones we need help with, you can [filter for merged PRs](https://github.com/expressjs/expressjs.com/pulls?q=is%3Apr+is%3Aclosed+label%3Arequires-translation-es) that include the tag for your language, such as `requires-translation-es` for requires Spanish translation.
457+
1. Request to join the Express.js Website project on [Crowdin](https://express.crowdin.com/website)
458+
2. [Select the language you want to translate](https://support.crowdin.com/joining-translation-project/#starting-translation)
459+
3. [Start translating](https://support.crowdin.com/online-editor/)
488460

489-
If you contribute a page or section translation, please reference the original PR. This helps the person merging your translation to remove the tag from the original PR.

0 commit comments

Comments
 (0)