How to use the restify.serveStatic function in restify

To help you get started, we’ve selected a few restify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github covcom / 304CEM / 2015 / 2015 05 RESTful APIs / 02 RESTful APIs / gallery / index.js View on Github external
})
})

server.get('/gallery', (req, res) => {
  gallery.getAllPhotos(req, (err, data) => {
    res.setHeader('content-type', 'application/json')
    if (err) {
      res.send(400, {status: 'error', message: err.message })
    } else {
      res.send(202, {status: 'success', message: 'gallery retrieved', data: data})
    }
  })
})

/* we set up a route to serve static files from the 'photos/' directory. */
server.get(/photos\/?.*/, restify.serveStatic({
    directory: __dirname
}))

var port = process.env.PORT || 8080
server.listen(port, function (err) {
    if (err) {
        console.error(err)
    } else {
        console.log('App is ready at : ' + port)
    }
})
github microsoft / BotBuilder-V3 / Node / examples / hello-AzureWebApp / server.js View on Github external
appId: process.env.BOTFRAMEWORK_APPID, 
    appSecret: process.env.BOTFRAMEWORK_APPSECRET
};

// Create bot and add dialogs
var bot = new builder.BotConnectorBot(botConnectorOptions);
bot.add('/', function (session) {
    session.send('Hello World');
});

// Setup Restify Server
var server = restify.createServer();
server.post('/api/messages', bot.verifyBotFramework(), bot.listen());

// Serve a static web page
server.get(/.*/, restify.serveStatic({
    'directory': '.',
    'default': 'index.html'
}));

server.listen(process.env.port || 1337, function () {
    console.log('%s listening to %s', server.name, server.url);
});
github NGRP / node-red-contrib-viseo / node-red-contrib-botbuilder / lib / server.js View on Github external
server.listen(opt.port || CONFIG.server.port, ()  => {
        if (verbose) info('Server "' + server.name + '" listening to ' + server.url);

        // Serve static files
        let root = process.cwd() + '/webapp/';
        if (verbose) info("Serve static files on "+ root);
        server.get(/\/static\/?.*/, restify.serveStatic({
            directory: root,
            default: 'index.html',
            charSet: 'utf-8',
        }));

        callback(undefined, server);
    });
}
github FabMo / FabMo-Engine / shopbot-api / routes.js View on Github external
module.exports = function(server) {


	/************** file module ****************/
	server.get('/files', files_module.get_files); //tested
	server.get('/run_file/:id', files_module.run_file); //tested
	server.post('/upload',files_module.upload_file); //tested

	/************** status module ****************/
	server.get('/status', status_module.get_status); //tested

	/************** commands module ****************/
	server.get('/stop',commands_module.stop);
  	
  	// Define the routes
	server.get(/.*/, restify.serveStatic({
  		directory: './static'
		}));
	
};
github etiennepinchon / magixjs / compiler / index.js View on Github external
// ----------------------------------------------

server.get('/api/:url', function (req, res, next) {
	var body = 'something';
	res.writeHead(200, {
		'Content-Length': Buffer.byteLength(body),
		'Content-Type': 'text/html'
	});
	res.write(body);
	res.end();

	return next();
});

// Static files
server.get(/\/sources\/?.*/, restify.serveStatic({
		directory: '../'//__dirname
}));

server.get(/\/test\/?.*/, restify.serveStatic({
		directory: '../'//__dirname
}));

// ----------------------------------------------

var wrench = require("wrench");
var uglify = require("uglify-js");
var path = require('path');

var walk = function(dir, done) {
	var results = [];
	fs.readdir(dir, function(err, list) {
github xpush / node-xpush / lib / server / session-server.js View on Github external
SessionServer.prototype.static = function(_path, _config) {

  //if(this.isStarted){
  this.server.get(_path, restify.serveStatic(_config));
  //}else{
  //  this.methods.staticFiles[_path] = _config;
  //}
};
github francisypl / mineranker / app.js View on Github external
module.exports = app; // for testing

var config = {
    appRoot: __dirname // required config
};

app.use(
  function crossOrigin(req,res,next){
      res.header('Access-Control-Allow-Origin', '*');
      res.header('Access-Control-Allow-Headers', 'X-Requested-With');
      return next();
  }
);

app.get('/', restify.serveStatic({
    directory: './build/mineranker',
    default: 'index.html'
}));

app.get(/\/.*\..*/, restify.serveStatic({
    directory: './build/mineranker',
    default: 'index.html'
}));

SwaggerRestify.create(config, function(err, swaggerRestify) {
    if (err) {
        throw err;
    }

    swaggerRestify.register(app);
github phodal / freerice / server / app.js View on Github external
server.get('/all/account', get_response.findAllAccount);
server.get('/account/id/:id', get_response.getAccountById);
server.get('/account/name/:name', get_response.getAccountByName);

server.post('/account/create', auth.create);
server.post('/login/user', auth.login);

server.get('/all/rice', rice.findAllRice);
server.post('/rice/create', rice.create);

server.get('/', restify.serveStatic({
    directory: 'web',
    default: 'index.html'
}));

server.get(/\/?.*/, restify.serveStatic({
    directory: 'web'
}));


server.listen(8080, function () {
    'use strict';
    console.log('%s listening at %s', server.name, server.url);
});
github covcom / 304CEM / 2015 / 2015 05 RESTful APIs / 02 RESTful APIs / bookshop / index.js View on Github external
console.log('POST /accounts')
  const auth = req.authorization
  const body = req.body
  console.log(body)
  const host = req.headers.host
  console.log(typeof req.files)
  accounts.add(host, auth, body, req.files, function(data) {
    console.log('DATA RETURNED')
    console.log(data)
    res.setHeader('content-type', 'application/json');
    res.send(data.code, data.response);
    res.end();
  })
})

server.get(/images\/?.*/, restify.serveStatic({
    directory: __dirname
}))

fs.mkdir('images', function(err) {
  if (err) {
    console.log('error creating images directory')
  }
  console.log('images directory created')
})

var port = process.env.PORT || 8080;
server.listen(port, function (err) {
  if (err) {
      console.error(err);
  } else {
    console.log('App is ready at : ' + port);
github FabMo / FabMo-Engine / routes / dashboard.js View on Github external
module.exports = function(server) {
    server.post('/apps', submitApp);
    server.get('/apps', getApps);
    server.get('/apps/:id', getAppInfo);
    server.get('/apps/:id/config', getAppConfig);
    server.post('/apps/:id/config', postAppConfig);
    server.del('/apps/:id', deleteApp);
    server.get('/apps/:id/files', listAppFiles);
    server.get(/\/approot\/?.*/, restify.serveStatic({
        directory: config.getDataDir('approot'),
    }));
    server.get('/updater', updater);

};