Skip to content

Commit 731ca84

Browse files
authored
Merge pull request #2 from AegisJSProject/patch/setup
Initial Setup
2 parents 39bf9a1 + e36e2f3 commit 731ca84

File tree

12 files changed

+198
-549
lines changed

12 files changed

+198
-549
lines changed

CHANGELOG.md

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -7,87 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
## [v1.1.3] - 2025-11-21
11-
12-
### Added
13-
- Add `npm start` script
14-
15-
### Changed
16-
- Update npm publishing
17-
18-
## [v1.1.2] - 2025-05-01
19-
20-
### Changed
21-
- Use `eslint` & `rollup` directly instead of by other packages
22-
- Update node version via `.npmrc`
23-
- Update Node CI workflow
24-
- Install & use `@shgysk8zer0/eslint-config`
25-
- Add support for `node --test`, including ignoring tests for publishing
26-
- Update ESLint & super-linter
27-
- Switch to more basic Rollup config
28-
- Update `exports` and `main` accordingly
29-
30-
### Fixed
31-
- Fix missed renaming in README
32-
33-
## Removed
34-
- Remove old ESLint config files
35-
36-
## [v1.1.1] - 2023-09-24
37-
38-
### Added
39-
- Add `unpkg` to `package.json`
40-
- Add badges in README
41-
42-
### Changed
43-
- Update `exports` to `package.json` to handle wider variety
44-
45-
### Fixed
46-
- Fix typo in `fix:js` script
47-
48-
### [v1.1.0] - 2023-07-03
49-
50-
### Changed
51-
- Update to node 20
52-
- Update npm publishing GH Action
53-
54-
## [v1.0.5] - 2023-07-02
55-
56-
### Added
57-
- Add `funding`
58-
59-
### Changed
60-
- Updated GitHub Actions workflows
61-
- Update versioning & lock-file scripts
62-
- Update `.npmignore` & `.gitignore`
63-
64-
## [v1.0.4] - 2023-06-08
65-
66-
### Added
67-
- Install `@shgysk8zer0/npm-utils`
68-
- Add `exports` to package config
69-
70-
### Removed
71-
- Uninstall `rollup`, `eslint`
72-
73-
### Changed
74-
- Use `getConfig()` from `@shgysk8zer0/js-utils/rollup` for rollup config
75-
76-
## [v1.0.3] - 2023-06-01
77-
78-
### Fixed
79-
- Revert to old Release Action, now with permissions & link to changelog
80-
81-
## [v1.0.2] - 2023-06-01
82-
83-
### Fixed
84-
- Fix `changelog-entry` to match `[$version]` instead of `$version`
85-
86-
## [v1.0.1] - 2023-05-31
87-
88-
### Fixed
89-
- Update GitHub Release workflow to use [Auto Release](https://github.com/marketplace/actions/auto-release)
90-
91-
## [v1.0.0] - 2023-05-31
10+
## [v1.0.0] - 2025-11-21
9211

9312
Initial Release

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
# npm-template
1+
# `@aegisjsproject/dev-server`
22

3-
A template repo for npm packages
3+
Dev server setup for `@shgysk8zer0/http-server`
44

5-
[![CodeQL](https://github.com/shgysk8zer0/npm-template/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/shgysk8zer0/npm-template/actions/workflows/codeql-analysis.yml)
6-
![Node CI](https://github.com/shgysk8zer0/npm-template/workflows/Node%20CI/badge.svg)
7-
![Lint Code Base](https://github.com/shgysk8zer0/npm-template/workflows/Lint%20Code%20Base/badge.svg)
5+
[![CodeQL](https://github.com/AegisJSProject/dev-server/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/AegisJSProject/dev-server/actions/workflows/codeql-analysis.yml)
6+
![Node CI](https://github.com/AegisJSProject/dev-server/workflows/Node%20CI/badge.svg)
7+
![Lint Code Base](https://github.com/AegisJSProject/dev-server/workflows/Lint%20Code%20Base/badge.svg)
88

9-
[![GitHub license](https://img.shields.io/github/license/shgysk8zer0/npm-template.svg)](https://github.com/shgysk8zer0/npm-template/blob/master/LICENSE)
10-
[![GitHub last commit](https://img.shields.io/github/last-commit/shgysk8zer0/npm-template.svg)](https://github.com/shgysk8zer0/npm-template/commits/master)
11-
[![GitHub release](https://img.shields.io/github/release/shgysk8zer0/npm-template?logo=github)](https://github.com/shgysk8zer0/npm-template/releases)
9+
[![GitHub license](https://img.shields.io/github/license/AegisJSProject/dev-server.svg)](https://github.com/AegisJSProject/dev-server/blob/master/LICENSE)
10+
[![GitHub last commit](https://img.shields.io/github/last-commit/AegisJSProject/dev-server.svg)](https://github.com/AegisJSProject/dev-server/commits/master)
11+
[![GitHub release](https://img.shields.io/github/release/AegisJSProject/dev-server?logo=github)](https://github.com/AegisJSProject/dev-server/releases)
1212
[![GitHub Sponsors](https://img.shields.io/github/sponsors/shgysk8zer0?logo=github)](https://github.com/sponsors/shgysk8zer0)
1313

14-
[![npm](https://img.shields.io/npm/v/@shgysk8zer0/npm-template)](https://www.npmjs.com/package/@shgysk8zer0/npm-template)
15-
![node-current](https://img.shields.io/node/v/@shgysk8zer0/npm-template)
16-
![npm bundle size gzipped](https://img.shields.io/bundlephobia/minzip/@shgysk8zer0/npm-template)
17-
[![npm](https://img.shields.io/npm/dw/@shgysk8zer0/npm-template?logo=npm)](https://www.npmjs.com/package/@shgysk8zer0/npm-template)
14+
[![npm](https://img.shields.io/npm/v/@aegisjsproject/dev-server)](https://www.npmjs.com/package/@aegisjsproject/dev-server)
15+
![node-current](https://img.shields.io/node/v/@aegisjsproject/dev-server)
16+
![npm bundle size gzipped](https://img.shields.io/bundlephobia/minzip/@aegisjsproject/dev-server)
17+
[![npm](https://img.shields.io/npm/dw/@aegisjsproject/dev-server?logo=npm)](https://www.npmjs.com/package/@aegisjsproject/dev-server)
1818

1919
[![GitHub followers](https://img.shields.io/github/followers/shgysk8zer0.svg?style=social)](https://github.com/shgysk8zer0)
20-
![GitHub forks](https://img.shields.io/github/forks/shgysk8zer0/npm-template.svg?style=social)
21-
![GitHub stars](https://img.shields.io/github/stars/shgysk8zer0/npm-template.svg?style=social)
20+
![GitHub forks](https://img.shields.io/github/forks/AegisJSProject/dev-server.svg?style=social)
21+
![GitHub stars](https://img.shields.io/github/stars/AegisJSProject/dev-server.svg?style=social)
2222
[![Twitter Follow](https://img.shields.io/twitter/follow/shgysk8zer0.svg?style=social)](https://twitter.com/shgysk8zer0)
2323

2424
[![Donate using Liberapay](https://img.shields.io/liberapay/receives/shgysk8zer0.svg?logo=liberapay)](https://liberapay.com/shgysk8zer0/donate "Donate using Liberapay")

consts.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

favicon.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const FAVICON = `<svg width="16" height="16" viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg">
2+
<rect width="10" height="10" x="0" y="0" rx="1" ry="1" fill="#${crypto.getRandomValues(new Uint8Array(3)).toHex()}"></rect>
3+
</svg>`;
4+
5+
export default () => new Response(FAVICON, { headers: { 'Content-Type': 'image/svg+xml' }});

home.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { readFile } from 'node:fs/promises';
2+
import { imports } from '@shgysk8zer0/importmap';
3+
4+
const pkg = JSON.parse(await readFile(process.cwd() + '/package.json', { encoding: 'utf8' }));
5+
6+
const importmap = JSON.stringify({
7+
imports: {
8+
...imports,
9+
[pkg.name]: pkg.exports['.'].import,
10+
[`${pkg.name}/`]: './',
11+
}
12+
});
13+
14+
const sri = async (input) => await Promise.resolve(input)
15+
.then(json => new TextEncoder().encode(json))
16+
.then(bytes => crypto.subtle.digest('SHA-384', bytes))
17+
.then(hash => 'sha384-' + new Uint8Array(hash).toBase64());
18+
19+
const integrity = await sri(importmap);
20+
21+
const CSP = `default-src 'self'; style-src 'self' https://unpkg.com/@agisjsproject/ blob:; script-src 'self' https://unpkg.com/@shgysk8zer0/ https://unpkg.com/@kernvalley/ https://unpkg.com/@aegisjsproject/ '${integrity}'; image-src 'self' https://i.imgur.com/ https://secure.gravatar.com/avatar/ blob: data:; media-src 'self' blob:; frame-src https://www.youtube-nocookie.com; trusted-types aegis-sanitizer#html aegis-router#html; require-trusted-types-for 'script';`;
22+
23+
export default async (req) => {
24+
const doc = await readFile(process.cwd() + '/index.html', { encoding: 'utf8' });
25+
26+
const request = JSON.stringify({
27+
url: req.url,
28+
method: req.method,
29+
destination: req.destination,
30+
mode: req.mode,
31+
cache: req.cache,
32+
referrer: req.referrer,
33+
headers: Object.fromEntries(req.headers),
34+
}, null, 4);
35+
36+
return new Response(
37+
doc
38+
.replaceAll('{{ IMPORTMAP }}', importmap)
39+
.replaceAll('{{ INTEGRITY }}', integrity)
40+
.replaceAll('{{ POLYFILLS }}', imports['@shgysk8zer0/polyfills'])
41+
.replaceAll('{{ REQUEST }}', request),
42+
{
43+
headers: {
44+
'Content-Type': 'text/html',
45+
'Content-Security-Policy': CSP,
46+
}
47+
}
48+
);
49+
};

http.config.js

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,10 @@
1-
import { readFile } from 'node:fs/promises';
2-
import { imports } from '@shgysk8zer0/importmap';
3-
4-
const pkg = JSON.parse(await readFile('./package.json', { encoding: 'utf8' }));
5-
6-
const importmap = JSON.stringify({
7-
imports: {
8-
...imports,
9-
[pkg.name]: pkg.exports['.'].import,
10-
[`${pkg.name}/`]: './',
11-
}
12-
});
13-
14-
const sri = async (input) => await Promise.resolve(input)
15-
.then(json => new TextEncoder().encode(json))
16-
.then(bytes => crypto.subtle.digest('SHa-384', bytes))
17-
.then(hash => 'sha384-' + new Uint8Array(hash).toBase64());
18-
19-
const integrity = await sri(importmap);
20-
21-
const headers = new Headers({
22-
'Content-Type': 'text/html',
23-
'Content-Security-Policy': `default-src 'self'; style-src 'self' blob:; script-src 'self' https://unpkg.com/@shgysk8zer0/ https://unpkg.com/@kernvalley/ https://unpkg.com/@aegisjsproject/ '${integrity}'; trusted-types aegis-sanitizer#html; require-trusted-types-for 'script';`,
24-
});
1+
import home from '@aegisjsproject/dev-server';
2+
import favicon from '@aegisjsproject/dev-server/favicon';
253

264
export default {
27-
routes: {
28-
'/': async (req) => {
29-
const doc = await readFile('./index.html', { encoding: 'utf8' });
30-
const request = JSON.stringify({
31-
url: req.url,
32-
method: req.method,
33-
destination: req.destination,
34-
mode: req.mode,
35-
cache: req.cache,
36-
referrer: req.referrer,
37-
headers: Object.fromEntries(req.headers),
38-
}, null, 4);
39-
40-
return new Response(
41-
doc
42-
.replaceAll('{{ IMPORTMAP }}', importmap)
43-
.replaceAll('{{ INTEGRITY }}', integrity)
44-
.replaceAll('{{ POLYFILLS }}', imports['@shgysk8zer0/polyfills'])
45-
.replaceAll('{{ REQUEST }}', request),
46-
{ headers }
47-
);
48-
},
49-
'/favicon.svg': () => {
50-
const svg = `<svg width="16" height="16" viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg">
51-
<rect width="10" height="10" x="0" y="0" rx="1" ry="1" fill="#${crypto.getRandomValues(new Uint8Array(3)).toHex()}"></rect>
52-
</svg>`;
53-
54-
return new Response(svg, {
55-
headers: { 'Content-Type': 'image/svg+xml' },
56-
});
57-
}
58-
},
595
open: true,
6+
routes: {
7+
'/': home,
8+
'/favicon.svg': favicon,
9+
}
6010
};

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html lang="en" dir="ltr">
33
<head>
4-
<title>Test</title>
4+
<title>Dev Server</title>
55
<meta charset="utf-8" />
66
<meta name="viewport" content="width=device-width" />
77
<meta name="color-scheme" content="light dark" />

index.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

index.test.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)