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

fix: replace ReactSSRCommonMiddleware with ReactSSREntry #10

Merged
merged 1 commit into from
Dec 26, 2021
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
3 changes: 2 additions & 1 deletion examples/shell/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const path = require("path");
const polka = require("polka");
const serveStatic = require("serve-static");
const url = require("url");
const {ReactSSREntry, ReactSSRResponse} = require("../../utils");
const {ReactSSREntry} = require("../../src/ReactSSREntry");
const {ReactSSRResponse} = require("../../src/ReactSSRResponse");

// eslint-disable-next-line no-magic-numbers
const workdir = path.resolve(process.cwd(), process.argv.slice(2)[0] || ".");
Expand Down
14 changes: 0 additions & 14 deletions utils.js → src/ReactSSREntry.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/* eslint-disable max-statements */
const {match} = require("path-to-regexp");
const {isPlainObject} = require("is-plain-object");
Expand Down Expand Up @@ -36,19 +35,6 @@ async function ReactSSREntry({require, workdir, props, url, version}) {
}
}

function ReactSSRResponse(res, result) {
const {body, statusCode} = result;
res.writeHead(
statusCode,
{
"Content-Type": body.startsWith("<!DOCTYPE html>") ? "text/html" : "text/plain",
}
);
res.end(body);
return;
}

module.exports = {
ReactSSREntry,
ReactSSRResponse,
};
3 changes: 2 additions & 1 deletion src/ReactSSRMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require("fs");
const {patchFs, patchRequire} = require("fs-monkey");
const {ReactSSREntry, ReactSSRResponse} = require("../utils");
const {ReactSSRResponse} = require("./ReactSSRResponse");
const {ReactSSREntry} = require("./ReactSSREntry");
const {PLUGIN_NAME} = require("./ReactSSRWebpackPlugin");
const url = require("url");

Expand Down
15 changes: 15 additions & 0 deletions src/ReactSSRResponse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function ReactSSRResponse(res, result) {
const {body, statusCode} = result;
res.writeHead(
statusCode,
{
"Content-Type": body.startsWith("<!DOCTYPE html>") ? "text/html" : "text/plain",
}
);
res.end(body);
return;
}

module.exports = {
ReactSSRResponse,
};
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const {ReactSSRWebpackPlugin, PLUGIN_NAME} = require("./ReactSSRWebpackPlugin");
const {ReactSSRMiddleware} = require("./ReactSSRMiddleware");
const {ReactSSREntry} = require("./ReactSSREntry");

module.exports = {
PLUGIN_NAME,
ReactSSREntry,
ReactSSRMiddleware,
ReactSSRWebpackPlugin,
};