Find Jobs
Hire Freelancers

Node.js/Express.js site for CORS scripts

$100-200 USD

Anulowano
Opublikowano ponad 11 lat temu

$100-200 USD

Płatne przy odbiorze
I need to build a back end server in Node.js or [login to view URL] that allows Web pages hosted by third parties to perform AJAX calls (since they would be running in third party sites, they would be Cross-Origin Resource Sharing [login to view URL]) So I need two Node applications. One called Alice, that has the scripts, and another called Bob that published a simple Web page that includes jQuery and consumes the scripts from Alice using AJAX-CORS. Alice API is capable of using different back end scripts depending on data received to start the script. Also, Alice holds session data for each client using the script and is capable of executing multiple exchanges with multiple clients while keeping track of the next script instruction to process for each client. There are detailed workflow examples as well as a description for the user interface of the Bob site in the detailed specifications. The resulting web page must work in Windows in IE 8 and 9, Google Chrome and Firefox. Ideally in Safari in MacOS but if you only have a Windows computer to test this is no big deal. ## Deliverables The bob web site can be run locally using node 0.8.9 and [login to view URL] 3.0.0 in port 3001. It presents a single web page that contains a text area where some lines of text can be entered and a text input to enter an optional script number to process in the server. There is also a button to start processing the server script as described in the following sections. Bob also includes a script reference to a module that resides in the Alice web site and is loaded from there. Something like the following entry in the Jade template in Bob: script(type='text/javascript', src='http://localhost:3000/[login to view URL]') Alice runs also in node 0.8.9 and [login to view URL] 3.0.0 using port 3000 and has two entry points /init and /next It also publishes the script that third party web sites can load as a public resource in the root. The text entered in the text area in the Bob web application has a first line that is always a four digit number followed by one or more lines of text to be sent to Alice. **Exchange Workflow.** When the user presses the button in the Bob page, there is a function in [login to view URL] that makes a CORS AJAX call to /init in Alice sending the script number to use that is the value entered in the text input if any, and if the user leaves that field empty then the first line of the text entered in the text area is the script number (that will be ignored in case there is a value in the forced script number text input.). When Alice receives a call to init, it creates a new session, and assigns to it the code of the script that is processed for that user ([login to view URL]) Then the Alice site loads a module with that particular script and sends a response back to the client that contains a JSON object with a command (cmd) that can be 'NEXT' or 'END' and optionally a result (res). In [login to view URL] the call to /init uses a callback to a function Next defined in that same script that analyses the result from the server and acts on it. If the 'cmd' from the server is 'NEXT' then in the client we take the following line in the text area and send it via an AJAX CORS call to the server to the /next entypoint. If the 'cmd' is 'END' then we just show the 'res' value from the server response and the processing stops. When the server receives data from the client to the /next entrypont, it continues building a string that basically concatenates the data received from the client with data in the script file and keeps that in the session object for that particular exchange. Then it goes to the next line in the module that corresponds to the particular script being processes, and if there is a following line in responds again with 'NEXT' to get the next line from the client. When there are no more lines in the script in the server, the response contains the 'cmd' 'END' and here it includes the built string in the 'res' member of the JSON response. When [login to view URL] in Bob web site receives a final 'END' it just displays the result string. **Startup Pseudo Code** // [login to view URL] function Init(){ $.ajax( url: http://localhost:3000/init data {script: 0001} callback= Next } function Next(response) { if ([login to view URL] = 'NEXT') // Get next line from the text area .ajax ( url: http://localhost:3000/next data {line: "sometext"} callback= Next else if ([login to view URL] = 'END') [login to view URL]("The server built the string" + [login to view URL]) } [login to view URL], running from http://localhost:3001 <html> <head> <script type='text/javascript' scr='http://localhost:3000/[login to view URL]'> </head> <body> <input textarea> <input text id='forcescript'> <input button onclick="Init()"> </body> </html> Alice app dir: // [login to view URL] [login to view URL]('/init', [login to view URL]) [login to view URL]('/next', [login to view URL]) // /routes/[login to view URL] [login to view URL] = function([login to view URL]) { [login to view URL] ... } [login to view URL] = function([login to view URL]) { var script = require('./script' + [login to view URL]); var response = {} [login to view URL] = [login to view URL](req); [login to view URL]([login to view URL](response)); } // /routes/script0001 switch [login to view URL] **Worked Examples** The scripts on the server can be just some special way to write the instructions inside a normal node.js module or can be more sophisticated with some specific DSL but this is not really required. The only importan thing on the server is to be able to keep track of the sequence of the operation, so the result can be processes in multiple back and forth calls from the client to the server. If the text in the textarea in [login to view URL] contains for example 0001 One Two Three Fourt And the scripts are the following: 0001 First Second Third 0002 AA BB CC DD 0003 Short The resulting string would just be the following: 0001 'One First Two Second Three Third' 0002 'One AA Two BB Three CC Four DD' 0003 'One Short' **Pitfalls** In fact building the servers is not so difficult, for a node expert is probably even very easy. The real challenge is CORS with different browsers and adding calls to preflight OPTIONS calls made by Chrome, and making it work in IE 8 and 9 since those browsers don't allow cookies in CORS. This means that probably you will have to build some other way to manage sessions than the one provided by Express. Also, is probably better to use POST requests but if you see a good reason why GET would be a better option that could be ok. I guess if you read all this, you will have questions so I'll be happy to answer them before you bid if necessary.
Identyfikator projektu: 2779676

Informację o projekcie

3 ofert
Zdalny projekt
Aktywny 11 lat temu

Szukasz sposobu na zarobienie pieniędzy?

Korzyści ze składania ofert na Freelancer.com

Ustal budżet i ramy czasowe
Otrzymuj wynagrodzenie za swoją pracę
Przedstaw swoją propozycję
Rejestracja i składanie ofert jest bezpłatne
3 freelancerzy składają oferty o średniej wysokości $153 USD dla tej pracy
Awatar Użytkownika
See private message.
$150 USD w 15 dni
5,0 (9 opinii)
4,1
4,1
Awatar Użytkownika
See private message.
$140,25 USD w 15 dni
5,0 (1 opinia)
1,3
1,3
Awatar Użytkownika
See private message.
$170 USD w 15 dni
0,0 (0 opinii)
0,0
0,0

O kliencie

Flaga UNITED STATES
United States
5,0
7
Członek od lut 20, 2011

Weryfikacja Klienta

Dziękujemy! Przesłaliśmy Ci e-mailem link do odebrania darmowego bonusu.
Coś poszło nie tak podczas wysyłania wiadomości e-mail. Proszę spróbować ponownie.
Zarejestrowani Użytkownicy Całkowita Liczba Opublikowanych Projektów
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Wczytywanie podglądu
Udzielono pozwolenia na Geolokalizację.
Twoja sesja logowania wygasła i zostałeś wylogowany. Proszę, zalogować się ponownie.