How to use the serveStatic function from restify

Find comprehensive JavaScript restify.serveStatic code examples handpicked from public code repositorys.

133
134
135
136
137
138
139
140
141
// Message
server.post('/api/message/', post_message);

// Static Content /////////////////////////////////////////////

server.get(/\/(css|img|js)?.*/, restify.serveStatic({
  directory: './static',
  default: 'index.html'
}));
fork icon22
star icon75
watch icon6

+ 3 other calls in file

23
24
25
26
27
28
29
30
31
32
  res.status(200);
  res.header('Content-Type', 'text/html');
  res.end(data.toString().replace(/host:port/g, req.header('Host')));
});

app.get(/\/(css|js|img)\/?.*/, restify.serveStatic({directory: __dirname+'/static'}));

app.listen(config.get('PORT'), config.get('IP'), function () {
  console.log( "Listening on " + config.get('IP') + ", port " + config.get('PORT') )
});
fork icon43
star icon49
watch icon7

43
44
45
46
47
48
49
50
51
52
    name: { isRequired: true, scope: 'body' },
    email: { isRequired: true, isEmail: true, scope: 'body' },
    website: { isRequired: true, isUrl: true, scope: 'body' }
  }
}, api.register);
server.get(/\/developers\/api-explorer\/?.*/, restify.serveStatic({
  directory: __dirname + '/..',
  default: 'index.html'
}));
server.get(/\/examples\/browser\/?.*/, restify.serveStatic({
fork icon9
star icon12
watch icon22

+ 7 other calls in file

14
15
16
17
18
19
20
21
22
23
24
25
    .use(restify.bodyParser())
    .use(restify.CORS());


controller.context(server, '/todo/api', model);


server.get(/\/todo\/?.*/, restify.serveStatic({
    'directory': __dirname,
    'default': 'index.html'
}));

fork icon0
star icon1
watch icon0

+ 2 other calls in file

259
260
261
262
263
264
265
266
267
268
    serve_get_category);
pkg_server.get(pkg_prefix + '/api/set/:set/category/:category',
    serve_get_catinfo);

/* HTML */
staticfunc = mod_restify.serveStatic({
    directory: mod_path.join(__dirname, 'html')
});

pkg_server.get(new RegExp('^' + pkg_prefix + '/set.*/'),
fork icon0
star icon0
watch icon0

+ 2 other calls in file

187
188
189
190
191
192
193
194
195
196
197
198
199
200


    // static files: /, /index.html, /images...
    //var STATIS_FILE_RE = /\/?\.css|\/?\.js|\/?\.png|\/?\.jpg|\/?\.gif|\/?\.jpeg|\/?\.less|\/?\.eot|\/?\.svg|\/?\.ttf|\/?\.otf|\/?\.woff|\/?\.pdf|\/?\.ico|\/?\.json|\/?\.wav|\/?\.mp3/;
    var STATIS_FILE_RE = /\.(css|js|jpe?g|png|gif|less|eot|svg|bmp|tiff|ttf|otf|woff|pdf|ico|json|wav|ogg|mp3?|xml|woff2|map)$/i;
    server.get(STATIS_FILE_RE, restify.plugins.serveStatic({ directory: './public/docs', default: 'index.html', maxAge: 0 }));
//    server.get(/^\/((.*)(\.)(.+))*$/, restify.serveStatic({ directory: './TruMenuWeb', default: "index.html" }));






    server.get(/\.html$/i,restify.plugins.serveStatic({
fork icon0
star icon0
watch icon0

83
84
85
86
87
88
89
90
        /**
         * Server static content. a light wrapper.
         * @param options
         */
        serverStatic: function(options) {
                return restify.serveStatic(options);
        }
};
fork icon0
star icon0
watch icon1

+ 9 other calls in file

26
27
28
29
30
31
32
33
34
35
  //console.log(genres);
  res.send(genres_ids);
})

//serve static content
server.get(/\/.*/, restify.serveStatic({
    directory: './public',
    default: 'index.html'
}));
 
fork icon0
star icon0
watch icon0