@expo/server
Advanced tools
Comparing version 0.4.4-canary-20240628-1ba8152 to 0.4.4
@@ -8,10 +8,9 @@ "use strict"; | ||
require("@expo/server/install"); | ||
const node_fs_1 = __importDefault(require("node:fs")); | ||
const node_path_1 = __importDefault(require("node:path")); | ||
const debug = process.env.NODE_ENV === 'development' | ||
? require('debug')('expo:server') | ||
: () => { }; | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = __importDefault(require("path")); | ||
const url_1 = require("url"); | ||
const debug = require('debug')('expo:server'); | ||
function getProcessedManifest(path) { | ||
// TODO: JSON Schema for validation | ||
const routesManifest = JSON.parse(node_fs_1.default.readFileSync(path, 'utf-8')); | ||
const routesManifest = JSON.parse(fs_1.default.readFileSync(path, 'utf-8')); | ||
const parsed = { | ||
@@ -41,3 +40,3 @@ ...routesManifest, | ||
function getRoutesManifest(distFolder) { | ||
return getProcessedManifest(node_path_1.default.join(distFolder, '_expo/routes.json')); | ||
return getProcessedManifest(path_1.default.join(distFolder, '_expo/routes.json')); | ||
} | ||
@@ -48,5 +47,5 @@ exports.getRoutesManifest = getRoutesManifest; | ||
// Serve a static file by exact route name | ||
const filePath = node_path_1.default.join(distFolder, route.page + '.html'); | ||
if (node_fs_1.default.existsSync(filePath)) { | ||
return node_fs_1.default.readFileSync(filePath, 'utf-8'); | ||
const filePath = path_1.default.join(distFolder, route.page + '.html'); | ||
if (fs_1.default.existsSync(filePath)) { | ||
return fs_1.default.readFileSync(filePath, 'utf-8'); | ||
} | ||
@@ -56,16 +55,16 @@ // Serve a static file by route name with hoisted index | ||
const hoistedFilePath = route.page.match(/\/index$/) | ||
? node_path_1.default.join(distFolder, route.page.replace(/\/index$/, '') + '.html') | ||
? path_1.default.join(distFolder, route.page.replace(/\/index$/, '') + '.html') | ||
: null; | ||
if (hoistedFilePath && node_fs_1.default.existsSync(hoistedFilePath)) { | ||
return node_fs_1.default.readFileSync(hoistedFilePath, 'utf-8'); | ||
if (hoistedFilePath && fs_1.default.existsSync(hoistedFilePath)) { | ||
return fs_1.default.readFileSync(hoistedFilePath, 'utf-8'); | ||
} | ||
return null; | ||
}, getApiRoute = async (route) => { | ||
const filePath = node_path_1.default.join(distFolder, route.file); | ||
const filePath = path_1.default.join(distFolder, route.file); | ||
debug(`Handling API route: ${route.page}: ${filePath}`); | ||
// TODO: What's the standard behavior for malformed projects? | ||
if (!node_fs_1.default.existsSync(filePath)) { | ||
if (!fs_1.default.existsSync(filePath)) { | ||
return null; | ||
} | ||
if (/\.[cj]s$/.test(filePath)) { | ||
if (/\.c?js$/.test(filePath)) { | ||
return require(filePath); | ||
@@ -80,3 +79,3 @@ } | ||
const params = {}; | ||
const url = new URL(request.url); | ||
const url = new url_1.URL(request.url); | ||
const match = config.namedRegex.exec(url.pathname); | ||
@@ -110,3 +109,3 @@ if (match?.groups) { | ||
} | ||
const url = new URL(request.url, 'http://expo.dev'); | ||
const url = new url_1.URL(request.url, 'http://expo.dev'); | ||
const sanitizedPathname = url.pathname; | ||
@@ -113,0 +112,0 @@ debug('Request', sanitizedPathname); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.respond = exports.convertRequest = exports.convertHeaders = exports.createRequestHandler = void 0; | ||
const stream_1 = require("@remix-run/node/dist/stream"); | ||
const node_1 = require("@remix-run/node"); | ||
const __1 = require(".."); | ||
@@ -58,3 +58,3 @@ /** | ||
if (req.method !== 'GET' && req.method !== 'HEAD') { | ||
init.body = (0, stream_1.createReadableStreamFromReadable)(req); | ||
init.body = (0, node_1.createReadableStreamFromReadable)(req); | ||
// @ts-expect-error | ||
@@ -73,3 +73,3 @@ init.duplex = 'half'; | ||
if (expoRes.body) { | ||
await (0, stream_1.writeReadableStreamToWritable)(expoRes.body, res); | ||
await (0, node_1.writeReadableStreamToWritable)(expoRes.body, res); | ||
} | ||
@@ -76,0 +76,0 @@ else { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.respond = exports.convertHeaders = exports.convertRequest = exports.createRequestHandler = void 0; | ||
const stream_1 = require("@remix-run/node/dist/stream"); | ||
const node_1 = require("@remix-run/node"); | ||
const __1 = require(".."); | ||
@@ -42,3 +42,3 @@ /** | ||
if (req.method !== 'GET' && req.method !== 'HEAD') { | ||
init.body = (0, stream_1.createReadableStreamFromReadable)(req); | ||
init.body = (0, node_1.createReadableStreamFromReadable)(req); | ||
// @ts-expect-error | ||
@@ -74,3 +74,3 @@ init.duplex = 'half'; | ||
if (expoRes.body) { | ||
await (0, stream_1.writeReadableStreamToWritable)(expoRes.body, res); | ||
await (0, node_1.writeReadableStreamToWritable)(expoRes.body, res); | ||
} | ||
@@ -77,0 +77,0 @@ else { |
@@ -62,3 +62,3 @@ "use strict"; | ||
res.statusMessage = expoRes.statusText; | ||
res.writeHead(expoRes.status, expoRes.statusText, [...expoRes.headers.entries()].flat()); | ||
res.writeHead(expoRes.status, expoRes.statusText, [...expoRes.headers.entries()]); | ||
if (expoRes.body) { | ||
@@ -65,0 +65,0 @@ await (0, node_1.writeReadableStreamToWritable)(expoRes.body, res); |
{ | ||
"name": "@expo/server", | ||
"version": "0.4.4-canary-20240628-1ba8152", | ||
"version": "0.4.4", | ||
"description": "Server API for Expo Router projects", | ||
@@ -45,3 +45,3 @@ "main": "build/index.js", | ||
}, | ||
"gitHead": "1ba815237ed606c5ee8488f68e49773fc9735cc3" | ||
"gitHead": "f83423bebc947ad7e328daaa56b2e327912ae580" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
51572
824