### Running WebDemo with Alternate Start Location (Bash) Source: https://github.com/fpc/pas2js/blob/main/demo/fpreport/README.md This example demonstrates how to run the webdemo project with the '-s' or '--start' option to specify an alternate HTML file as the starting point. This is useful for serving the pas2js front-end from a specific location. ```bash # Example usage: home:~/fpc/packages/fcl-report/demos> ./webdemo -s /home/michael/source/pas2js/demo/fpreport/reportdemo.html Point your browser to http://localhost:8080/Page or http://localhost:8080 An alternate start location is available at http://localhost:8080/Start/reportdemo.html ``` -------------------------------- ### Start FPC Websocket Server (Shell) Source: https://github.com/fpc/pas2js/blob/main/demo/websockets/README.md Command to start the FPC websocket server example application. It listens on a specified port for incoming connections. ```shell wsserver -p 8080 ``` -------------------------------- ### HTML Structure for PushJS Hello World Source: https://github.com/fpc/pas2js/blob/main/demo/pushjs/helloworld.html This HTML snippet provides the basic structure for the PushJS 'Hello World' demo. It includes a link to the PushJS library and a button element that will be styled and interacted with. ```html PushJS - Hello world!
``` -------------------------------- ### Start Node.js Server for Parameterized Routes Source: https://github.com/fpc/pas2js/blob/main/demo/router/README.md This command starts a Node.js server using the 'histsrv2.js' script. This server is configured to handle requests for 'demorouter2.html', which likely includes routes with parameters. Similar to the previous server example, it ensures that unknown URLs are directed to the main HTML file to support client-side routing. ```shell nodejs histsrv2.js ``` -------------------------------- ### CSS Styling for PushJS Demo Source: https://github.com/fpc/pas2js/blob/main/demo/pushjs/helloworld.html This CSS code defines the styling for the PushJS 'Hello World' demo. It includes styles for the body background, centering content, and a distinct appearance for the button, including hover effects. ```css body { background-color: #e1e1e1; } .center { margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); } .button { background-color: #4CAF50; border: none; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; -webkit-transition-duration: 0.4s; /* Safari */ transition-duration: 0.4s; border-radius: 8px; } .button:hover { box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19); } ``` -------------------------------- ### Pas2js Configuration File Example Source: https://context7.com/fpc/pas2js/llms.txt An example of a `pas2js.cfg` configuration file, illustrating various compiler options. This includes display settings, operator handling, unit search paths, conditional compilation for Node.js, combining output, and setting the output directory. ```cfg # Display logo and verbosity -l -vwnh # Allow C-style operators (+=, -=, etc.) -Sc # Unit search paths (wildcards supported) -Fu$CfgDir/../packages/rtl -Fu$CfgDir/../packages/fcl-base -Fu$CfgDir/../packages/fcl-json # Conditional compilation for Node.js #IFDEF nodejs -Jirtl.js #ENDIF # Combine all JavaScript into one file -Jc # Output directory -FE./js ``` -------------------------------- ### Run Simple Web Server (Shell) Source: https://github.com/fpc/pas2js/blob/main/demo/websockets/README.md Command to start a simple web server in the current directory. This is used to serve the chat client's HTML and JavaScript files. ```shell simpleserver -p 3000 ``` -------------------------------- ### Apache Proxy Configuration for Data Abstract Source: https://github.com/fpc/pas2js/blob/main/demo/dataabstract/README.txt Configures Apache to forward requests to a Data Abstract application server. This allows the Data Abstract server to be accessed via a specific URL path. Adjust the port and path as per your server setup. ```apache ProxyPass "http://127.0.0.1:8099/" ``` -------------------------------- ### Simpleserver Configuration for Data Abstract Proxy Source: https://github.com/fpc/pas2js/blob/main/demo/dataabstract/README.txt Configures simpleserver to act as a proxy for a Data Abstract server. This involves setting the port simpleserver listens on, the directory for static files, and the URL of the Data Abstract server. ```ini [Server] ; Correct these Port=6789 Directory=/home/michael/pas2js/demo/dataabstract [Proxy] Server=http://127.0.0.1:8099/ ``` -------------------------------- ### PAS2JS Data Abstract Connection (Read-Write) Source: https://github.com/fpc/pas2js/blob/main/demo/dataabstract/README.txt Configures a Data Abstract connection for read-write operations in PAS2JS. It specifies the URL of the Data Abstract server. Ensure the URL correctly points to your running Data Abstract server. ```pascal FConn:=TDaConnection.Create(Self); FConn.URL:='/proxy/Server/bin'; ``` -------------------------------- ### Start Node.js Server for Static Routes Source: https://github.com/fpc/pas2js/blob/main/demo/router/README.md This command initiates a Node.js server using the 'histsrv.js' script. This server is designed to handle requests for the 'demorouter.html' file, serving it as the main page. It's crucial for applications using the hash history model to ensure that any unknown URL is redirected to the main HTML file, allowing the client-side router to take over. ```shell nodejs histsrv.js ``` -------------------------------- ### Node.js HTTP Server with Free Pascal Source: https://context7.com/fpc/pas2js/llms.txt Provides an example of creating a basic HTTP server using Free Pascal's Node.js bindings. It demonstrates handling incoming requests, setting response headers and status codes, and sending different responses based on the URL path, including serving dynamic data like the current time. ```pascal program NodeServer; {$mode objfpc} uses nodejs, node.http, browserconsole, SysUtils; procedure HandleRequest(req: TNJSHTTPServerRequest; res: TNJSHTTPServerResponse); var url: string; responseData: string; begin url := req.url; Writeln('Request: ', req.method_, ' ', url); res.statusCode := 200; res.setHeader('Content-Type', 'text/html'); if url = '/' then responseData := '

Welcome to pas2js server!

' else if url = '/api/time' then responseData := Format('{"time": "%s"}', [DateTimeToStr(Now)]) else begin res.statusCode := 404; responseData := '

404 Not Found

'; end; res._end(responseData); end; var server: TNJSHTTPServer; port: integer; begin port := 3000; server := TNJSHTTP.createServer(@HandleRequest); server.listen(port, lambda begin Writeln('Server running at http://localhost:', port, '/'); end ); end. ``` -------------------------------- ### Install vsce Package Manager Source: https://github.com/fpc/pas2js/blob/main/demo/vscode/helloworld/README.md Installs the 'vsce' command-line tool globally, which is required for packaging VS Code extensions. This is a prerequisite for creating the .vsix distribution file. ```sh npm install -g vsce ``` -------------------------------- ### Package VS Code Extension Source: https://github.com/fpc/pas2js/blob/main/demo/vscode/helloworld/README.md Packages the VS Code extension into a .vsix file for distribution. This command should be run in the project's root directory after installing vsce. ```sh vsce package ``` -------------------------------- ### jQuery Integration with Free Pascal Source: https://context7.com/fpc/pas2js/llms.txt Shows how to integrate the jQuery library with Free Pascal code to manipulate the DOM. This example demonstrates setting styles, creating HTML elements, appending them to the body, and attaching event handlers, specifically a click handler for a button. ```pascal program jQueryDemo; uses libjquery, browserconsole; procedure SetupPage; begin // Set page styles jQuery('body').css('font-family', 'Arial, sans-serif'); // Create and style elements jQuery('

').text('Hello from pas2js!').appendTo('body'); jQuery('
') .attr('id', 'content') .addClass('container') .css('background', '#f0f0f0') .css('padding', '20px') .appendTo('body'); // Add click handler jQuery('