PHP Classes

File: tests/e2e/serve.mjs

Recommend this page to a friend!
  Packages of Alberto Arena   Laravel Truss   tests/e2e/serve.mjs   Download  
File: tests/e2e/serve.mjs
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Laravel Truss
View a diagram of a Laravel application models
Author: By
Last change:
Date: 9 days ago
Size: 1,141 bytes
 

Contents

Class file image Download
// Minimal static file server for the Playwright harness. Serves the repo root // so the harness page, the shipped ES modules under resources/js, and Mermaid // from node_modules all load same-origin (native module imports need that). import { createServer } from 'node:http'; import { readFile } from 'node:fs/promises'; import { extname, join, normalize } from 'node:path'; const root = process.cwd(); const port = Number(process.env.PORT || 5178); const TYPES = { '.html': 'text/html', '.js': 'text/javascript', '.mjs': 'text/javascript', '.css': 'text/css', '.json': 'application/json', '.map': 'application/json', }; createServer(async (req, res) => { try { const pathname = new URL(req.url, 'http://localhost').pathname; const safe = normalize(decodeURIComponent(pathname)).replace(/^(\.\.[/\\])+/, ''); const body = await readFile(join(root, safe)); res.writeHead(200, { 'content-type': TYPES[extname(safe)] || 'application/octet-stream' }); res.end(body); } catch { res.writeHead(404); res.end('not found'); } }).listen(port, () => console.log(`truss e2e static server on ${port}`));