0.0.9 • Published 6 years ago

@singcl/express v0.0.9

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Express@singcl

🐠 Express

Travis npm (scoped) code style: prettier David David npm

A counterfeit Express.

Usage

npm i @singcl/express -S

example

// var opn = require('opn')
var error = require('@singcl/express-error')
var express = require('@singcl/express')
var app = express()

app.use(function(req, res, next) {
    // 告诉客户端以UTF-8的方式解析 设置charset=utf-8解决前端拿到的数据中文乱码
    res.setHeader('Content-Type', 'text/plain;charset=utf-8')
    // next('[全局]-中间件错误捕获:next(err)')
    next()
})

app.get('/example', function(req, res, next) {
    // 告诉客户端以UTF-8的方式解析 设置charset=utf-8解决前端拿到的数据中文乱码
    res.setHeader('Content-Type', 'text/plain;charset=utf-8')
    next('[路由]-中间件错误捕获:next(err)')
})

app.get('/user', function(req, res, next) {
    // 告诉客户端以UTF-8的方式解析 设置charset=utf-8解决前端拿到的数据中文乱码
    res.setHeader('Content-Type', 'text/plain;charset=utf-8')
    res.write('来自星星的你', 'utf8')
    res.end(function() {
        console.log('数据已发送!')
    })
})

app.post('/user', function(req, res, next) {
    // 告诉客户端以UTF-8的方式解析 设置charset=utf-8解决前端拿到的数据中文乱码
    res.setHeader('Content-Type', 'text/plain;charset=utf-8')
    res.write('来自星星的POST', 'utf8')
    res.end(function() {
        console.log('post数据已发送!')
    })
})

// 错误中间件use - 自定义如何处理错误
app.use(error())

// 
app.listen(3000, function() {
    console.log('node server start at port 3000!')
    // opn('http://127.0.0.1:3000')
})

LicenseFOSSA Status

FOSSA Status

badge: https://img.shields.io/

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago