Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Server \ Using Ruby to build a simple HTTP service and sass environment     - CentOS 6.5 installation and simple configuration Nginx (Server)

- Copy Recovery using RMAN repository development environment (Database)

- Use backup-manager system backup on Linux (Linux)

- Java, hashcode, equals and == (Programming)

- Install Oracle 11g illustrations and dependent libraries under SUSE11 (Database)

- Linux Network Programming - raw socket instance: MAC Address Scanner (Programming)

- Getting Started with Linux system to learn: how to install autossh (Linux)

- NAT and firewall under Linux (Linux)

- Linux data recovery software efficiently practical application extundelete (Linux)

- Linux operating system Start Tutorial: Xmanager Remote Access Linux graphical interface (Linux)

- About redis in Replication (Database)

- Use Ansible installation NGINX and NGINX Plus (Server)

- MySQL Tutorial: Using tpcc-mysql pressure measurement (Database)

- Linux disk partition, format, mount the directory (Linux)

- Teamviewer not start in Linux (Linux)

- Linux automatically install service components and optimize the kernel parameters (Linux)

- Ubuntu install Scala 2.10.x version (Linux)

- Parameters of the extra port MySQL 5.6 (Database)

- Java generate two-dimensional code by Zxing (Programming)

- Linux tool curl and wget advanced use (Linux)

 
         
  Using Ruby to build a simple HTTP service and sass environment
     
  Add Date : 2018-11-21      
         
         
         
  Since the front-end development under normal circumstances, we may need to have an http service, of course, you can choose to write a node's http service is relatively simple, such as the following node of code:

var PORT = 3000;

var http = require ( 'http');

var url = require ( 'url');

var fs = require ( 'fs');

var mine = {

  "Css": "text / css",

  "Gif": "image / gif",

  "Html": "text / html",

  "Ico": "image / x-icon",

  "Jpeg": "image / jpeg",

  "Jpg": "image / jpeg",

  "Js": "text / javascript",

  "Json": "application / json",

  "Pdf": "application / pdf",

  "Png": "image / png",

  "Svg": "image / svg + xml",

  "Swf": "application / x-shockwave-flash",

  "Tiff": "image / tiff",

  "Txt": "text / plain",

  "Wav": "audio / x-wav",

  "Wma": "audio / x-ms-wma",

  "Wmv": "video / x-ms-wmv",

  "Xml": "text / xml"

};

var path = require ( 'path');

var server = http.createServer (function (request, response) {

    var pathname = url.parse (request.url) .pathname;

    console.log (pathname)

    var realPath = pathname.substr (1); // path.join ( "assets", pathname);

    console.log (realPath);

    var ext = path.extname (realPath);

    ext = ext ext.slice (1): 'unknown';?

    fs.exists (realPath, function (exists) {

        if (! exists) {

            response.writeHead (404, {

                'Content-Type': 'text / plain'

            });

 

            response.write ( "This request URL" + pathname + "was not found on this server.");

            response.end ();

        } Else {

            fs.readFile (realPath, "binary", function (err, file) {

                if (err) {

                    response.writeHead (500, {

                        'Content-Type': 'text / plain'

                    });

                    response.end (err);

                } Else {

                    var contentType = mine [ext] || "text / plain";

                    response.writeHead (200, {

                        'Content-Type': contentType

                    });

                    response.write (file, "binary");

                    response.end ();

                }

            });

        }

    });

});

server.listen (PORT);

console.log ( "Server runing at port:" + PORT + ".");

But this is too much trouble every time copy this file to the project directory, and the installation environment is also needed ruby sass, so we need to understand the next gem install sass and asdf.

Pilot official website to download a ruby, after installation, you can use

gem install sass

Command to install other components, such as to install sass environment. If you want to install the beta version, you can enter the command line

gem install sass --pre

Upgrade command is

gem update sass

Today we want to install http asdf such a service, we first use

gem install asdf

After installation is complete, you can access when you need to use a folder directory

asdf -p 8080

Then you can use http: // localhost: 8080 / to access the current directory of the http service.

Since the domestic network reasons, it may lead rubygems.org stored in Amazon S3 above resource files intermittent connection failures. At this time we can gem sources command to configure the source, first remove the default https://rubygems.org source, and then add Taobao source https://ruby.taobao.org/, then you look at the source is currently in use which, if Taobao, then you can enter the gem install sass installation command.

$ Gem sources --remove https://rubygems.org/
$ Gem sources -a https://ruby.taobao.org/
$ Gem sources -l
*** CURRENT SOURCES ***
https://ruby.taobao.org
# Make sure that only ruby.taobao.org
$ Gem install sass
     
         
         
         
  More:      
 
- Android Studio Personalization (Linux)
- Stucts2 values on the page and how the attribute values corresponding to the Action (Programming)
- Sort sql MySQL 5.6 upgrade slow Cause Analysis (Database)
- After installing minimize RHEL / CentOS 7 we need to do (Linux)
- Linux file compression and archiving (Linux)
- iOS constants, variables, properties and characteristics (Programming)
- Linux system security configuration (Linux)
- Django1.8 return json json string and the string contents of the received post (Programming)
- Boost-- time and date - (1) timer library introduction (Programming)
- Linux user groups, file permissions Detailed (Linux)
- ASM Disk Space Check (Database)
- Configuring Proxy on a Unix terminal, accelerate Android Studio Construction (Linux)
- To teach you how to safely send mail (Linux)
- Linux stand-alone OGG synchronous Oracle 11g DB test (Database)
- Linux Shell Understanding and Learning (Linux)
- Java synchronization mechanism: synchronized, wait, notify (Programming)
- CentOS 6.x and CentOS7 install MPlayer (Linux)
- CentOS 6.5 installation and simple configuration Nginx (Server)
- Linux Security Raiders SSH tools SCP uses examples to explain in detail (Linux)
- CentOS 6.6 running level (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.