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

Simplify dev server #1026

Merged
merged 1 commit into from
May 16, 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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ FROM nginx:1.24.0-alpine
RUN rm -r /usr/share/nginx/html && rm /etc/nginx/conf.d/default.conf
# Copy pattern library static assets, and put them in nginx document root folder
COPY --from=builder /frontend-shared/build /usr/share/nginx/html
COPY ./templates/pattern-library.mustache /usr/share/nginx/html/index.html
COPY ./templates/index.html /usr/share/nginx/html/index.html
COPY ./images /usr/share/nginx/html/images
COPY conf/nginx.conf /etc/nginx/conf.d/default.conf

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"karma-source-map-support": "^1.4.0",
"mocha": "10.2.0",
"mustache": "^4.2.0",
"mustache-express": "^1.3.0",
"plop": "^3.1.1",
"postcss": "^8.3.9",
"preact": "^10.5.6",
Expand Down
11 changes: 6 additions & 5 deletions scripts/serve-pattern-library.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import express from 'express';
import log from 'fancy-log';
import mustacheExpress from 'mustache-express';
import * as path from 'path';
import { fileURLToPath } from 'url';

export function servePatternLibrary(port = 4001) {
const dirname = path.dirname(fileURLToPath(import.meta.url));
const app = express();
app.engine('mustache', mustacheExpress());
app.set('view engine', 'mustache');
app.set('views', [path.join(dirname, '../templates')]);

// Map paths from which we serve static files
app.use('/scripts', express.static(path.join(dirname, '../build/scripts')));
app.use('/styles', express.static(path.join(dirname, '../build/styles')));
app.use('/images', express.static(path.join(dirname, '../images')));

// For any other path, serve the index.html file to allow client-side routing
app.get('/:path?', (req, res) => {
res.render('pattern-library');
res.sendFile(path.join(dirname, '../templates/index.html'));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From express docs:

How do I render plain HTML?
You don’t! There’s no need to “render” HTML with the res.render() function. If you have a specific file, use the res.sendFile() function

https://expressjs.com/en/starter/faq.html#how-do-i-render-plain-html

});

app.listen(port, () => {
Expand Down
2 changes: 1 addition & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import tailwindPreset from './src/tailwind.preset.js';

export default {
presets: [tailwindPreset],
content: ['./src/**/*.{js,ts,tsx}', './templates/**/*.mustache'],
content: ['./src/**/*.{js,ts,tsx}', './templates/**/*.html'],
};
File renamed without changes.
16 changes: 1 addition & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1859,11 +1859,6 @@ async-settle@^1.0.0:
dependencies:
async-done "^1.2.2"

async@~3.2.0:
version "3.2.3"
resolved "https://registry.yarnpkg.com/async/-/async-3.2.3.tgz#ac53dafd3f4720ee9e8a160628f18ea91df196c9"
integrity sha512-spZRyzKL5l5BZQrr/6m/SqFdBN0q3OCI0f9rjfBzCMBIP4p75P620rR3gTmaksNOhmzgdxcaxdNfMy6anrbM0g==

atob@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz"
Expand Down Expand Up @@ -5454,7 +5449,7 @@ lower-case@^2.0.2:
dependencies:
tslib "^2.0.3"

lru-cache@^5.1.1, lru-cache@~5.1.1:
lru-cache@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920"
integrity sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==
Expand Down Expand Up @@ -5691,15 +5686,6 @@ ms@2.1.3:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==

mustache-express@^1.3.0:
version "1.3.2"
resolved "https://registry.yarnpkg.com/mustache-express/-/mustache-express-1.3.2.tgz#fe0aa129cfc42bfe6fa4dbd191eba5303ba04785"
integrity sha512-yAdGHctEq9ubUH7h9O6Z6kW35fwfE+7LpW/TBrcfVibZuiVRHDcK8DEydgiU5nlJmJUY5VC3jv2lzaPUL+Arkw==
dependencies:
async "~3.2.0"
lru-cache "~5.1.1"
mustache "^4.2.0"

mustache@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/mustache/-/mustache-4.2.0.tgz#e5892324d60a12ec9c2a73359edca52972bf6f64"
Expand Down