express

My Angular/Node/Express app serves index.html instead of static assets in production mode - why?

感情迁移 提交于 2020-01-14 05:51:10
问题 I have an Angular/Node/Express webapp built on generator-angular-fullstack . In development mode, the app works just fine. But in production mode, it serves index.html whenever static assets (images, CSS) are requested, and I can't figure out why - I guess something is wrong with my ExpressJS routing. lib/express.js: set path for static assets // Mode: Production app.configure('production', function(){ app.use(express.favicon(path.join(config.root, 'public', 'favicon.ico'))); app.use(express

How to do nested iterations in jade?

巧了我就是萌 提交于 2020-01-14 05:36:09
问题 ul li a(href='') menu1 li a(href='') menu2 ul li a(href='') sub-menu2 li a(href='') menu3 ul li a(href='') sub-menu3 ul li a(href='') secondary-submenu3 This is what I'm trying to achieve, instead of writing the above jade code I want to be able to generate it using loops. I tried the jade documentation, the examples show only one level of loop. For eg. I could try this -var menus = [ 'menu1', 'menu2', 'menu3' ]; ul each menu in menus li a(href='') #{menu} But this is not enough. if I try

Jade - calling page specific css pages

元气小坏坏 提交于 2020-01-14 05:34:10
问题 I have page specific css files I would like to call automatically. Does anyone have a nice way of doing this elegantly? 回答1: This should do it link(rel="stylesheet", href="#{req.path + '.css'}", type="text/css") Where you pass either req (the request object) as a local variable when rendering the jade template (or even just pass in req.path as path ). This could just be handled in your layout.jade and it will work for each of your route paths. If you want to get fancy, you could establish a

aws-serverless-express via AWS API gateway asking for authentication even not setup for that

与世无争的帅哥 提交于 2020-01-14 05:34:04
问题 sorry for such 101 question but I'm kinda new with AWS, NodeJS and Express. I'm setting up a basic serverless API Gateway: index.js import AwsServerlessExpress from 'aws-serverless-express'; import App from './src/app'; const server = AwsServerlessExpress.createServer(App); exports.handler = (event, context) => AwsServerlessExpress.proxy(server, event, context); ./src/app.js import Express from 'express'; import BodyParser from 'body-parser'; import AwsServerlessExpressMiddleware from 'aws

loopback angular 404 on refresh page

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-14 04:24:06
问题 I have create an application with loopback and angular but i have a problem. When i refresh the browser loopback give me a 404 url not Found. Added base tag to index.html <base href="/"/> Set middlelware.json properly to serve static content: "files": { "loopback#static": { "params": "$!../client" } Set HTML5 mode in angular router (I'm using ui-router) $locationProvider.html5Mode(true); $urlRouterProvider.otherwise('/'); I have yet deleted root.js from the project. What i'm doing wrong?

Mongoose findOne callback gives me null

六月ゝ 毕业季﹏ 提交于 2020-01-14 04:21:14
问题 In the code below obj receives null in the findOne callback. Don't understand why. In my database it looks like this. MongoDB shell version: 2.2.0 connecting to: test > use test switched to db test > db.Restaurant.findOne(); { "_id" : ObjectId("53372f9714b4d69cbfa2bbaf"), "name" : "Printz", "visit" : "2014-04-02 19:00:00" } Code app.js /** * Module dependencies. */ var express = require('express'); var http = require('http'); var path = require('path'); var moment = require('moment'); var

How to send some context from node server to html template without using any template engines

半腔热情 提交于 2020-01-14 04:10:09
问题 server.js app.get('/',(req,res) => { let context = {title:"api",message:"root"} res.sendFile(__dirname + '/views/index.html',context) }) index.html <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title></title> </head> <body> title{{title}} message{{message}} </body> </html> how can i send title and message to index.html which is assigned in contex variable. i found a lot of way to do it using some template engines like jade,ejs,pug etc.. but i want it in pure html.

Serve an i18n angular app on Firebase using functions

╄→гoц情女王★ 提交于 2020-01-14 04:08:10
问题 I'm trying to handle requests correctly to a localized angular app hosted on Firebase. The goal is to load the right app bundle depending on: 1) A cookie named locale . 2) The accept-language header. 3) Default to en-us when others are unavailable. When localizing angular apps with i18n, angular-cli generates bundles (versions of your app) for each language/locale present in angular.json . Firebase serves your bundles as static content and it has serious security measurements disallowing path

CORS validation for WEB Socket

被刻印的时光 ゝ 提交于 2020-01-14 03:40:47
问题 I'm using expressjs and added cors validation for a all origins. const options = { origin: ['*'], credentials: true, exposedHeaders: false, preflightContinue: false, optionsSuccessStatus: 204, methods: ['GET', 'POST'], allowedHeaders: allowedHeaders, }; module.exports = cors(options); This is enabling one of the two CORS requests that I'm using however, One of which is a response from server and the other one is a socket. I'm using angular observable to get the response like. const headers =

Uploading a base64 encoded image to Node.js server not working

为君一笑 提交于 2020-01-14 03:21:30
问题 I'm using MEAN.io and i'm trying to upload a base64 encoded image. Client side, AngularJS: // Image we're going to send it out var base64Image = files[i]; var file = { image: base64Image, type: type, filetype: extension, characterId: character._id }; var newFile = new MediaSendBase64(file); newFile.$save(function(image) { if ( !image ) { console.log('ERROR IMAGE'); } else { console.log('SUCCESS.'); console.log(image); } }); Server side, NodeJS, controller: app.use(bodyParser.json({limit: