Git Product home page Git Product logo

teaching-heigvd-cm_webs's Introduction

Links to repos

Heroku Setup

  1. Create your account on Heroku
  2. Follow the instruction to setup your computer. Only the instruction to install the required tools.
  3. Go to your project directory: cd <app directory>
  4. Run the following command: heroku create
  5. To deploy the app, run this command: git push heroku master or follow the specific instructions present in the app README.md.

Resources

HTTP return codes

Express - Mongoose example

var
  mongoose = require('mongoose'),
  Schema = mongoose.Schema;

// Issue type definition
var IssueType = new Schema({
  name: String,
  description: String
});

mongoose.model('IssueType', IssueType);

// Issue definition
var Issue = new Schema({
  description: String,
	// Default value on object creation
	updatedOn: { type: Date, default: Date.now },
	// ...
	issueType: { type: Schema.Types.ObjectId, ref: 'IssueType' }
});

// Hook applied before object saved to enrich the object data
Issue.pre('save', function(next) {
	this.updatedOn = new Date();
	next();
});

mongoose.model('Issue', Issue);

Issue.find()
	.populate('issueType')
	.exec(function(err, issues) {
		// Do something with the issues
	});

IssueType.findById("id", function(err, issueType) {
	var issue = new Issue({
		issueType: issueType
	});
})

var issue = new Issue({
	issueType: "id"
});

Express - Routing example

function authenticate(req, res, next) {
	// Try to retrieve the userId from HTTP headers
	var userId = req.headers['x-user-id'];

	if (userId != undefined) {
		// Try to retrieve the corresponding user
		User.findById(userId, function (err, user) {
			if (err || user === null) {
				res.status(401).end();
			}

			// If user has at least one role, then he is authorized to access the API
			else if (user.roles.length > 0) {
				req.user = user;
				// Continue the invocation chain
				next();
			}
			else {
				res.status(403).end();
			}
		});
	}
	else {
		res.status(401).end();
	}
},


module.exports = function (app) {
  app.use('/api/users', router);
};

// First possibility
router.route('/')
	.get(authenticate)
	.get(function(req, res, next) {
		User.find(function (err, users) {
		  if (err) return next(err);
		  res.json(users);
		});
	});

// Second possibility
router.route('/')
	.get(authenticate, function(req, res, next) {
		User.find(function (err, users) {
		  if (err) return next(err);
		  res.json(users);
		});
	});

// In this example, maybe we want to apply authentication to **ALL** resources (Maybe not a good idea for creating a new user!)
router.all('/api/*', authenticate);

Labo Delivery

Delivery date: 2nd of March 2015 at noon

Send a mail to laurent.prevost [at] heig-vd.ch with the following informations:

  • Link to the Documentation repository (raml content, customized static website)
  • Link to the Spring Boot implementation repository (even if it is not fully implemented)
  • Link to the Express implementation repository (even if it is not fully implemented)

We expect, at least, the following:

  • Each repository to contain the README.md updated with
    • Names of team members
    • Link to Heroku application deployed (if applicable, at least the doc and the chosen techno implementation)
  • RAML part
    • Whole documentation of your resources (it MUST be coherent with your implementation)
    • Customization of the static content (welcome page, blog articles, API ref main page)
    • In the footer, we expect to see the team member names
    • Somewhere in the static pages, we expect to find the link to Heroku application of your API implementation
    • In a blog post, indicates which technology you have chosen and the reasons of your choice.

Remember to match the requirements expressed in the blog post.

REMARK: Do not worry if you do not have an Express (JavaScript) fork when you have chosen to do the labo only in Spring Boot (Java). Just specify it in the blog post that indicates which techno you have chosen.

teaching-heigvd-cm_webs's People

Contributors

prevole avatar

Watchers

James Cloos avatar  avatar Olivier Liechti avatar Florent Plomb avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.