Skip to content

Commit

Permalink
Merge branch 'minor' into layer-tables-query
Browse files Browse the repository at this point in the history
  • Loading branch information
RobAndrewHurst committed Jan 20, 2025
2 parents 1039a6c + 08dee12 commit 257eb3e
Show file tree
Hide file tree
Showing 45 changed files with 2,874 additions and 3,871 deletions.
70 changes: 62 additions & 8 deletions express.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,65 @@
/**
@module express.js
@description
# Express.js 🚅
[Express](https://expressjs.com) is a minimal and flexible Node.js web application framework that provides a robust
set of features for web and mobile applications.
Our implementation provides the following endpoints and features:
- SAML authentication endpoints for Single Sign-On
- Rate-limited API endpoints for provider interactions
- Static file serving for documentation
- Security enhancements including header protection
The server implements the following core features:
- Rate limiting: 1000 requests per 1 min per IP
- Cookie parsing for session management
- JSON body parsing with 5MB limit for POST requests
- Static file serving with HTML extension support
## Security 🔐
- X-Powered-By header disabled
- Rate limiting enabled
- SAML authentication required for protected routes
## env
```env
PORT - Server port (default: 3000)
DIR - Base directory for routes
RATE_LIMIT - Maximum requests per window (default: 1000)
RATE_LIMIT_WINDOW - Time window in ms (default: 1 min)
```
@requires dotenv - Environment configuration loading
@requires express - Web application framework
@requires cookie-parser - HTTP cookie parsing middleware
@requires express-rate-limit - Rate limiting middleware
*/

require('dotenv').config();

const express = require('express');

const cookieParser = require('cookie-parser');
const rateLimit = require('express-rate-limit');

const app = express();

app.disable('x-powered-by');

const limiter = rateLimit({
windowMs: process.env.RATE_LIMIT_WINDOW ?? 1 * 60 * 1000, // 1 min
limit: process.env.RATE_LIMIT ?? 1000, //1000 requests per 1min
standardHeaders: 'draft-8',
legacyHeaders: false,
});

app.use(limiter);

app.use(
'/xyz',
express.static('docs', {
Expand Down Expand Up @@ -33,7 +87,13 @@ app.post(
api,
);

app.get(`${process.env.DIR || ''}/api/sign/:signer?`, api);
app.get(`${process.env.DIR || ''}/api/sign/:provider?`, api);

app.post(
`${process.env.DIR || ''}/api/sign/:provider?`,
express.json({ limit: '5mb' }),
api,
);

app.get(`${process.env.DIR || ''}/api/query/:template?`, api);

Expand Down Expand Up @@ -73,12 +133,6 @@ app.post(
api,
);

app.post(
`${process.env.DIR || ''}/saml/logout/callback`,
express.urlencoded({ extended: true }),
api,
);

app.get(`${process.env.DIR || ''}/view/:template?`, api);

app.get(`${process.env.DIR || ''}/:locale?`, api);
Expand Down
15 changes: 4 additions & 11 deletions jsdoc_xyz.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
{
"source": {
"include": [
"api",
"mod"
],
"include": ["api", "mod", "express.js"],
"includePattern": ".js$"
},
"plugins": [
"plugins/markdown"
],
"plugins": ["plugins/markdown"],
"opts": {
"encoding": "utf8",
"readme": "./api/README.md",
Expand All @@ -19,9 +14,7 @@
"theme_opts": {
"title": "XYZ",
"homepageTitle": "XYZ",
"static_dir": [
"./public/icons"
],
"static_dir": ["./public/icons"],
"favicon": "./public/icons/favicon.ico",
"menu": [
{
Expand All @@ -41,4 +34,4 @@
"hardwrap": false,
"idInHeadings": true
}
}
}
6 changes: 6 additions & 0 deletions lib/dictionaries/en.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,10 @@ export default {
locations: 'Locations',
no_locales: 'Your account has been verified and approved, but you do not have access to any locales. This is likely as an administrator has not given you the required roles. Please contact an administrator to resolve this.',
no_layers: 'No accessible layers in locale.',
csv_upload_import: 'Import From CSV',
csv_upload_success: 'Data imported successfully',
csv_upload_failed: 'Data import failed, please try again.',
csv_upload_number_of_columns_imported: 'The number of columns in your imported file',
csv_upload_number_of_columns_required: 'is not the same as the number of columns required',
csv_upload_rows_imported: 'Rows Imported',
};
2 changes: 1 addition & 1 deletion lib/ui/Dataview.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function show() {
}

//Show toolbar buttons if there are any
this.btnRow?.style.setProperty('display','block')
this.btnRow?.style.setProperty('display','flex')

this.target.style.display = 'block'
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/Tabview.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function addTab(entry) {
}

//Show toolbar buttons if there are any
entry.btnRow?.style.setProperty('display', 'block')
entry.btnRow?.style.setProperty('display', 'flex')
}

/**
Expand Down
27 changes: 26 additions & 1 deletion lib/ui/utils/jsonDataview.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ The jsonDataview module exports as default an object with a create method for JS
export default {
create,
toolbar: {
jsonfile
jsonfile,
csvupload
}
}

Expand Down Expand Up @@ -76,3 +77,27 @@ function jsonfile(dataview) {

return button;
}

function csvupload(dataview) {

dataview.toolbar.csvupload.label ??= 'CSV Upload'

dataview.toolbar.csvupload.input = mapp.utils.html.node`<input
type=file class="flat bold wide primary-colour"
accept=".csv"
onchange=${async e => {
if (!e.target.files[0]) return;
dataview.toolbar.csvupload.file = e.target.files[0]
const uploaded = await mapp.utils.csvUpload(
dataview.toolbar.csvupload.file,
dataview.toolbar.csvupload
);
dataview.setData(uploaded)
}}>`

return dataview.toolbar.csvupload.input;
}
3 changes: 3 additions & 0 deletions lib/utils/_utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const areSetsEqual = (a, b) => a.size === b.size && [...a].every(value => b.has(

import csvDownload from './csvDownload.mjs'

import csvUpload from './csvUpload.mjs'

import compose from './compose.mjs'

import convert from './convert.mjs'
Expand Down Expand Up @@ -82,6 +84,7 @@ export default {
compose,
copyToClipboard,
csvDownload,
csvUpload,
dataURLtoBlob,
formatNumericValue,
unformatStringValue,
Expand Down
Loading

0 comments on commit 257eb3e

Please sign in to comment.