1+ /*
2+ *******************
3+ *** Installers ***
4+ *******************
5+
6+ npm install express (app control)
7+ npm install body-parser (data transfer between pages >> forms and ajax)
8+ npm install color-blind (blindness simulator library)
9+ */
10+
11+ const express = require ( 'express' ) ;
12+ const bodyParser = require ( 'body-parser' ) ;
13+ const blinder = require ( 'color-blind' ) ;
14+ const app = express ( ) ;
15+
16+ // receive datas via json and ajax
17+ app . use ( bodyParser . json ( ) ) ;
18+ app . use ( bodyParser . urlencoded ( { extended : true } ) ) ;
19+
20+ // disable cors
21+ app . use ( function ( req , res , next ) {
22+ res . header ( "Access-Control-Allow-Origin" , "*" ) ;
23+ res . header ( "Access-Control-Allow-Headers" , "Origin, X-Requested-With, Content-Type, Accept" ) ; ;
24+ next ( ) ;
25+ } ) ;
26+
27+ // port to run
28+ app . listen ( 4000 , ( ) => {
29+ console . log ( 'All right on port 4000!' ) ;
30+ } ) ;
31+
32+ // post methods
33+ app . post ( '/simulatorProtanomaly' , function ( req , res ) {
34+ color = simuProtanomaly ( req . body . color ) ;
35+ console . log ( color ) ;
36+ res . send ( color ) ;
37+ } ) ;
38+
39+ app . post ( '/simulatorProtanopia' , function ( req , res ) {
40+ color = simuProtanopia ( req . body . color ) ;
41+ console . log ( color ) ;
42+ res . send ( color ) ;
43+ } ) ;
44+
45+ app . post ( '/simulatorDeuteranomaly' , function ( req , res ) {
46+ color = simuDeuteranomaly ( req . body . color ) ;
47+ console . log ( color ) ;
48+ res . send ( color ) ;
49+ } ) ;
50+
51+ app . post ( '/simulatorDeuteranopia' , function ( req , res ) {
52+ color = simuDeuteranopia ( req . body . color ) ;
53+ console . log ( color ) ;
54+ res . send ( color ) ;
55+ } ) ;
56+
57+ app . post ( '/simulatorTritanomaly' , function ( req , res ) {
58+ color = simuTritanomaly ( req . body . color ) ;
59+ console . log ( color ) ;
60+ res . send ( color ) ;
61+ } ) ;
62+
63+ app . post ( '/simulatorTritanopia' , function ( req , res ) {
64+ color = simuTritanopia ( req . body . color ) ;
65+ console . log ( color ) ;
66+ res . send ( color ) ;
67+ } ) ;
68+
69+ app . post ( '/simulatorAchromatomaly' , function ( req , res ) {
70+ color = simuAchromatomaly ( req . body . color ) ;
71+ console . log ( color ) ;
72+ res . send ( color ) ;
73+ } ) ;
74+
75+ app . post ( '/simulatorAchromatopsia' , function ( req , res ) {
76+ color = simuAchromatopsia ( req . body . color ) ;
77+ console . log ( color ) ;
78+ res . send ( color ) ;
79+ } ) ;
80+
81+ app . post ( '/simulatorAll' , function ( req , res ) {
82+ colors = simuAll ( req . body . color ) ;
83+ console . log ( colors ) ;
84+ res . send ( colors ) ;
85+ } ) ;
86+
87+ // simulator methods
88+ function simuProtanomaly ( hex_color ) { return blinder . protanomaly ( hex_color ) ; }
89+ function simuProtanopia ( hex_color ) { return blinder . protanopia ( hex_color ) ; }
90+ function simuDeuteranomaly ( hex_color ) { return blinder . deuteranomaly ( hex_color ) ; }
91+ function simuDeuteranopia ( hex_color ) { return blinder . deuteranopia ( hex_color ) ; }
92+ function simuTritanomaly ( hex_color ) { return blinder . tritanomaly ( hex_color ) ; }
93+ function simuTritanopia ( hex_color ) { return blinder . tritanopia ( hex_color ) ; }
94+ function simuAchromatomaly ( hex_color ) { return blinder . achromatomaly ( hex_color ) ; }
95+ function simuAchromatopsia ( hex_color ) { return blinder . achromatopsia ( hex_color ) ; }
96+
97+ function simuAll ( hex_color ) {
98+ results = [ ] ;
99+
100+ results . push ( blinder . protanomaly ( hex_color ) ) ;
101+ results . push ( blinder . protanopia ( hex_color ) ) ;
102+ results . push ( blinder . deuteranomaly ( hex_color ) ) ;
103+ results . push ( blinder . deuteranopia ( hex_color ) ) ;
104+ results . push ( blinder . tritanomaly ( hex_color ) ) ;
105+ results . push ( blinder . tritanopia ( hex_color ) ) ;
106+ results . push ( blinder . achromatomaly ( hex_color ) ) ;
107+ results . push ( blinder . achromatopsia ( hex_color ) ) ;
108+
109+ return results ;
110+ }
0 commit comments