Skip to content
En app som sköter generering av kurssida i Kurs- och programkatalogen. Sidan innehåller introducerande beskrivning, allmän information om kurs, kursplan och information om kurstillfällen.
JavaScript CSS HTML PHP Ruby Dockerfile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
i18n
public
server
test
.dockerignore
.gitignore
.scanignore
.travis.yml
Dockerfile
Dockerfile.in
LICENSE
README.md
app.js
docker-compose.yml
docker-compose.yml.in
docker.conf
gulpfile.js
nodemon.json
package-lock.json
package.json
webpackClientSize.html

README.md

node-web

In an attempt to simplify the process of starting up new node.js based projects, there exists two template projects to use as a foundation.

The two projects are node-web, a web server with express, and node-api, a RESTful api. Both of them use OpenID Connect and/or CAS as a mechanism for authorisation and authentication.

The projects can be found here: https://github.com/KTH/node-web https://github.com/KTH/node-api

It's important that we try to make changes that affect the template projects in the template projects themselves.

###Where do you keep you secrets? Secrets during local development are ALWAYS stored in a .env-file in the root of your project. This file should be in .gitignore. It needs to contain at least ldap connection URI and password in order for authentication to work properly:

LDAP_URI=ldaps://[usertname]@ldap.ref.ug.kth.se
LDAP_PASSWORD=[password]

During local development the defaults in serverSettings.js should work fine. If you need to make specific changes for your machine, add these to the .env-file. If you want changes that should be used by anyone developing your project, change the default variables in the settings-files.

###How do I use node-web template project for a project of my own?

  1. Create a new git repository on github.com/KTH (or other somewhere else).

  2. Clone the newly created repository locally by using:

git clone https://github.com/USER/REPOSITORY.git
  1. Navigate to the cloned project directory

  2. Add node-web or node-api as the upstream repository to use:

git remote add upstream https://github.com/KTH/node-web.git
  1. Fetch the latest changes/branches for the upstream repository (use your KTH login if prompted):
git fetch upstream
  1. Checkout the branch you want to use:
git checkout master
  1. Merge the changes from node-api into your cloned repository:
git merge upstream/master
  1. Solve merge conflicts and commit/push to your cloned repository.

To keep your cloned repository up to date with the upstream repository, just repeat steps 5-7 from above. Make sure to commit and push your existing changes before you merge!

###If your application is going to be proxied If your application is going to be proxied on www.kth.se/api/your-api-path make sure you set the following paths and properties.

  1. Make sure you add the proxy prefix path in your paths in /server/init/routing/paths.js e.g
monitor : {
  uri : '/api/node/_monitor',
  method : 'GET'
}
  1. Set you basePath property in /swagger.json e.g.
"basePath": "/api/node/v1"

Starting the server

Always start by installing dependencies:

$ npm install

Then you need to start the server:

$ npm start

This will

  1. run gulp build:dev once to build SASS-files, and prepare browser JavaScript files
  2. start nodemon which triggers restart when server-side files have been updated
  3. run gulp watch which triggers a rebuild of browser assets when files have been updated

To learn more about the gulp build process, checkout kth-node-build-commons

Debugging

Debugging in VS Code

If you start Mode.js from VS Code you can set breakpoints in your editor. The launch config will look like this:

{
    "type": "node",
    "request": "launch",
    "name": "Launch Program",
    "program": "${workspaceRoot}/app.js",
    "cwd": "${workspaceRoot}",
    "env": {
        "NODE_ENV": "development"
    }
}

Setting NODE_ENV is currently required.

You can’t perform that action at this time.