小编and*_*a86的帖子

nodejs强大的改变uploadDir

我有一个proyect,即时通讯试图完成我想上传图像我可以上传图像但不在上传用于上传的目录

好吧让代码:

 app.post('/register',function(req,res) 
    {
var form = new formidable.IncomingForm();
form.keepExtensions = true;
form.uploadDir ='./uploaded/';
form
    .on('error', function(err) {
        throw err;
    })

    .on('field', function(field, value) {
        //receive form fields here
    })

    /* this is where the renaming happens */
    .on ('fileBegin', function(name, file){
            //rename the incoming file to the file's name
            file.path = form.uploadDir + "/" + file.name;
    })

    .on('file', function(field, file) {
        //On file received
    })

    .on('progress', function(bytesReceived, bytesExpected) {
        //self.emit('progess', bytesReceived, bytesExpected)

        var percent = (bytesReceived / bytesExpected * …
Run Code Online (Sandbox Code Playgroud)

node.js express formidable

3
推荐指数
1
解决办法
4722
查看次数

我如何限制只访问ajax请求?

我用ajax req加载inicio.jade

$.ajax(
{
    url:'/inicio',
    cache: false,
    type: 'GET',
}).done(function(web)
{
    $('#contenido_nav_principal').fadeOut(600,function()
    {
        $('#contenido_nav_principal').empty();
        $('#contenido_nav_principal').html(web);
        $('#navegacion').animate({height:'600px'},200);
        $('#contenido_nav_principal').fadeIn(600);
    });
});
Run Code Online (Sandbox Code Playgroud)

从服务器中的这个地址

app.get('/inicio',routes.inicio.inicio);
Run Code Online (Sandbox Code Playgroud)

问题是我可以访问http://www.mypage.com/inicio页面

如果不是ajax请求,我如何限制只访问ajax请求并重定向到404错误页面

javascript ajax node.js express

3
推荐指数
1
解决办法
1805
查看次数

具有多个文件nodejs的路由

我想在多个文件中路由

var routes=require('./routes');
Run Code Online (Sandbox Code Playgroud)

在routes/index.js中

exports.inicio=require('./inicio')
exports.home=require('./home')
Run Code Online (Sandbox Code Playgroud)

在inicio.js

exports.index=function(req,res){res.render('index/index',{title: 'Bienvenido a Inmoweb'});}
Run Code Online (Sandbox Code Playgroud)

在home.js

exports.nosotros=function(req, res){res.render('index/nosotros',{title:'Nosotros'});}
Run Code Online (Sandbox Code Playgroud)

当我console.log(路线)

{
inicio: {index:[function]}, 
home: {nosotros:[function]}
}
Run Code Online (Sandbox Code Playgroud)

所以我打电话给应用程序

app.get('/',routes.inicio.index);
Run Code Online (Sandbox Code Playgroud)

但我想这样打电话

app.get('/',routes.index);
app.get('/nosotros',routes.nosotros);
Run Code Online (Sandbox Code Playgroud)

和console.log supose是????

{
  index:[function], 
  nosotros:[function]
}
Run Code Online (Sandbox Code Playgroud)

怎么做???tnx全部

javascript node.js express

2
推荐指数
1
解决办法
980
查看次数

怎么知道nginx是否正在压缩gzip?

这是nginx的de配置文件

gzip on;
    gzip_disable "msie6";
        # gzip_static on;
    gzip_min_length 1400; 
        gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 9;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css image/png image/gif image/jpg application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript applicacion/x-font-ttf font/opentype application/x;
Run Code Online (Sandbox Code Playgroud)

在谷歌分析器中出现js文件没有压缩,所以我添加到nodejs gzippo模块,这是回购

 //app.use(express.static(path.join(__dirname, 'public')));
  app.use(gzippo.staticGzip(path.join(__dirname, 'public')));
Run Code Online (Sandbox Code Playgroud)

当我添加模块谷歌说,js是gzipped,但在repo不说我怎么能添加CSS文件和图像文件到gzippo模块压缩

所以我怎么知道用nginx或nodejs gzippo模块压缩文件,我怎么能压缩otf文件?

javascript proxy reverse-proxy nginx node.js

0
推荐指数
1
解决办法
3907
查看次数

为Sublime Text for JavaScript添加语法突出显示

我有一个问题,在我的崇高文本2中,javascript的语法亮点采用此代码

this.init = function(){};
this.init : function(){},
Run Code Online (Sandbox Code Playgroud)

在浅蓝色中绘制"this",在绿色中绘制"init"

但在这种情况下......

this.init = null;
this.init : null,
Run Code Online (Sandbox Code Playgroud)

没有发生......我想在所有使用案例中突出"这个.*"

比如说

this.init = function()
this.init : function()
this.init : true
this.init = true
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点???

javascript sublimetext2

0
推荐指数
1
解决办法
4442
查看次数

Java中的Hashtable"Unresolved compilation"

这是我的班级

package main;

import java.util.Hashtable;

public class Information {

    private final static String name = "Info Name";
    private final static String direccion = "direction street number";

    Hashtable<String,String> coordenates = new Hashtable<String,String>();
    coordenates.put("lat", "36.564565465");
    coordenates.put("lng", "64.584616511");

}
Run Code Online (Sandbox Code Playgroud)

我从oracle文档中学到了很多东西

This example creates a hashtable of numbers. It uses the names of the numbers as keys:

   Hashtable<String, Integer> numbers
     = new Hashtable<String, Integer>();
   numbers.put("one", 1);
   numbers.put("two", 2);
   numbers.put("three", 3);
To retrieve a number, use the following code:

   Integer n = numbers.get("two"); …
Run Code Online (Sandbox Code Playgroud)

java java-ee java-ee-7

0
推荐指数
1
解决办法
68
查看次数

正则表达式函数4个字母和4个数字?

我不明白正则表达式是如何工作的所以对许多人来说这可能是一个简单的问题,但对我来说非常重要,一个人可以用简单的词语解释我如何使用它.

我需要在jquery中验证添加一个新函数

$.validator.addMethod("loginRegex",function(a,b){return this.optional(b)||/^[a-zA-Z\d]+$/.test(a)},"Solo se aceptan letras o numeros");
Run Code Online (Sandbox Code Playgroud)

这个函数只接受字母和数字,但如果你把FH374HD3验证返回我是真的,但我需要按顺序有效4个字母和4个数字,例如:"ABCD4578",只有字母和数字但是4个字母第一个和4个数字在末尾.

是有形的??? tnx全部!

javascript jquery

-1
推荐指数
1
解决办法
7723
查看次数