Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
Initial commit. Working express 4 server, parcel builder with hot rel…
Browse files Browse the repository at this point in the history
…oading. Prettier for auto formatting.

Started using nav-designsystem components
  • Loading branch information
matsbyfl committed Feb 28, 2020
0 parents commit 87b2f2a
Show file tree
Hide file tree
Showing 17 changed files with 7,025 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["@babel/preset-react", "@babel/preset-env"],
"plugins": [["@babel/plugin-transform-runtime"]]
}
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.idea
dist
node_modules/
.cache/
frontend/src/.DS_Store
frontend/fonts/
.vscode/
.env
dockerbuild.sh
package-lock.json

.DS_Store
yarn-error.log
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 100,
"semi": false,
"singleQuote": true
}
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @navikt/aura
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM node:13-alpine
# TODO
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# The MIT License

Copyright 2018 NAV (Arbeids- og velferdsdirektoratet) - The Norwegian Labour and Welfare Administration

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

# Nais deploy frontend

TODO

## Utvikling lokalt

npm install -g yarn
yarn run dev


## Henvendelser

For external contact one of:

- Mats Byfuglien ([email protected])

For NAV-employees use #nais on our internal Slack
56 changes: 56 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict'

const { host } = require('./server/config/config')
const express = require('express')
const favicon = require('serve-favicon')
var path = require('path')
const logger = require('morgan')
//const prometheus = require('prom-client')
const helmet = require('helmet')

//prometheus.collectDefaultMetrics()

const app = express()
app.use(
logger('dev', {
skip: function(req, res) {
return res.statusCode < 400
}
})
)

app.use(helmet())
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')))
const cors = function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', host)
res.setHeader('Access-Control-Allow-Credentials', 'true')
res.setHeader('Access-Control-Allow-Methods', 'GET')
res.setHeader(
'Access-Control-Allow-Headers',
'Origin, Content-Type, X-AUTHENTICATION, X-IP, Content-Type, Accept, Access-Control-Allow-Headers, Authorization, X-Requested-With'
)
return next()
}
app.use(cors)

app.use(express.json())
//app.set('trust proxy', 1)

// ROUTES
app.use('/static', express.static(path.join(__dirname, 'dist')))
//app.use('/', router)

app.get('*', (req, res) => {
res.sendFile('index.html', { root: './dist' })
})

// ERROR HANDLING
app.use((err, req, res, next) => {
res.locals.message = err.message
res.locals.error = req.app.get('env') === 'development' ? err : {}
console.log('Error ' + err)
res.status(err.status || 500).send(err)
next()
})

module.exports = app
38 changes: 38 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env node

const app = require('../app')
const { host, port } = require('../server/config/config')
const http = require('http')
var debug = require('debug')('http'),
name = 'deploy-frontend'

debug(`Starting up`, name)

app.set('port', port)

var server = http.createServer(app)
server.listen(port)
server.on('error', onError)
server.on('listening', onListening)

function onError(error) {
if (error.syscall !== 'listen') {
throw error
}

switch (error.code) {
case 'EACCES':
console.error(`Port ${port} requires elevated privileges`)
process.exit(1)
case 'EADDRINUSE':
console.error(`Port ${port} is already in use`)
process.exit(1)
default:
throw error
}
}

function onListening() {
var addr = server.address()
debug(`Listening on ${host}:${addr.port}`)
}
12 changes: 12 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Nais deploy</title>
<link rel="stylesheet" type="text/css" href="js/index.less" />
</head>
<body>
<div id="root"></div>
<script src="js/index.tsx"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions frontend/js/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
html, body {
margin: 0;

&, #root {
height: 100%;
}
}

* {
box-sizing: border-box;
}
19 changes: 19 additions & 0 deletions frontend/js/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as React from 'react';
import * as DOM from 'react-dom';

import { Hovedknapp } from 'nav-frontend-knapper';
import { Systemtittel } from 'nav-frontend-typografi';

import './index.less';

function Application() {
return (
<div>
<h1>Hei 4</h1>
<Systemtittel>Test from react</Systemtittel>
<Hovedknapp >Hei banan</Hovedknapp>
</div>
);
}

DOM.render(<Application />, document.getElementById('root'));
60 changes: 60 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "nais-deploy-frontend",
"version": "42.0.0",
"description": "Frontend for nais deploy",
"scripts": {
"build-watch": "parcel watch frontend/index.html --public-url /static",
"start-watch": "NODE_ENV=development DEBUG=http,deploy-frontend nodemon bin/www",
"dev": "concurrently --kill-others \"yarn run start-watch\" \"yarn run build-watch\"",
"build": "parcel build frontend/index.html --public-url /static",
"test": "echo \"TODO\" && exit 1",
"start": "node ./bin/www"
},
"dependencies": {
"concurrently": "^5.1.0",
"debug": "^4.1.1",
"express": "^4.17.1",
"helmet": "^3.21.3",
"http": "^0.0.0",
"morgan": "^1.9.1",
"prop-types": "^15.7.2",
"serve-favicon": "^2.5.0"
},
"devDependencies": {
"@babel/core": "^7.0.0-0",
"@babel/plugin-transform-runtime": "^7.8.3",
"@babel/preset-react": "^7.8.3",
"classnames": "^2.2.6",
"husky": "^4.2.3",
"less": "^3.11.1",
"lodash.throttle": "^4.1.1",
"nav-frontend-core": "^4.0.11",
"nav-frontend-js-utils": "^1.0.8",
"nav-frontend-knapper": "^1.0.39",
"nav-frontend-knapper-style": "^0.3.34",
"nav-frontend-typografi": "^2.0.17",
"nav-frontend-typografi-style": "^1.0.18",
"nodemon": "^2.0.2",
"parcel-bundler": "^1.12.4",
"prettier": "^1.19.1",
"pretty-quick": "^2.0.1",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"rimraf": "^3.0.2",
"typescript": "^3.8.2"
},
"nodemonConfig": {
"ignore": [
"dist/*",
"frontend/*"
]
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
},
"author": "@navikt/aura",
"license": "MIT",
"private": true
}
Binary file added public/favicon.ico
Binary file not shown.
10 changes: 10 additions & 0 deletions server/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
exports.port = 8080

if (process.env['NODE_ENV'] === 'production') {
//process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
exports.host = process.env['HOST'] || 'localhost'
//exports.sessionSecret = process.env['SESSION_SECRET'] || 'H3mligereEnnDetteBlirDetIkke!'
//exports.cookieDomain = ''
} else if (process.env['NODE_ENV'] === 'development') {
exports.host = 'localhost'
}
5 changes: 5 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"jsx": "react"
}
}
Loading

0 comments on commit 87b2f2a

Please sign in to comment.