start(input = {}) { const port = input.port || this.settings.port; this.app = express(); this.app.use(cors()); this.app.use(express.urlencoded({ extended: false })); this.app.use(express.json()); for (let i = 0; i < this.plugins.length; i += 1) { this.app.use(this.plugins[i]); } if (this.settings.serveBot) { this.app.use(express.static(path.join(__dirname, './public'))); } for (let i = 0; i < this.routers.length; i += 1) { this.app.use(this.settings.apiRoot, this.routers[i]); } if (port && port > 0) { this.app.listen(port, () => { const logger = this.container.get('logger'); logger.info(`${this.settings.tag} listening on port ${port}!`); }); } }
before((done) => { // creating temporary files that will be used by the tests bellow (they get // removed automatically by the tmp library) fs.writeFileSync(path.join(temporaryFolder, fileName), Array(1 * 1024).join('0')); fs.writeFileSync(path.join(temporaryFolder, fileNameWithoutExt), Array(1).join('0')); const app = express(); app.use('/', express.static(temporaryFolder)); server = app.listen(0, () => { done(); }); port = server.address().port; });
app.get('/',function(req,res){ //res.render('./../app/index.ejs',{}); var application = React.createFactory(require('./../app/components/GroceryItemList.jsx')); GroceryItem.find(function(error,doc){ var generated = React.renderToString(application({ items:doc })); res.render('./../app/index.ejs',{reactOutput:generated}); }) }).use(express.static(__dirname+'/../.tmp')).listen(3000,function(){console.log('listening to port 3000');});
tasks.push(function setupStaticRoutes(cb) { var staticDir = path.join(__dirname, "build", options.project); if (app.config.env === "production") { staticDir = path.join(__dirname, "deploy", options.project); } app.use("/public", express.static(staticDir)); var favicon = require("serve-favicon"); app.use(favicon(path.join(__dirname, "/assets/images/favicon.ico"))); cb(); });
private setUpExpress() { this.app = express() this.app.use(express.static(STATIC_PATH)) this.app.use(express.json()) // validation middlewares this.app.post(`${API_ENDPOINT}`, this.bookMiddleware) this.app.put(`${API_ENDPOINT}/:isbn`, this.bookMiddleware) this.app.put(`${API_ENDPOINT}/:isbn`, this.isbnMiddleware) this.app.delete(`${API_ENDPOINT}/:isbn`, this.isbnMiddleware) }