New svelte based UI

New letsencrypt enabling server.js

Archived version of original article
This commit is contained in:
Martin Donnelly 2020-04-17 14:27:14 +01:00
parent 445a0c0411
commit 754f3b9810
17 changed files with 4382 additions and 5106 deletions

2
.gitignore vendored
View File

@ -98,7 +98,7 @@ crashlytics-build.properties
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## Build generated ## Build generated
build/ # build/
DerivedData DerivedData
## Various settings ## Various settings

25
app.js
View File

@ -16,16 +16,16 @@ logger.level = 'debug';
const Url = require('./models/url'); const Url = require('./models/url');
let isProduction = false; let isProduction = false;
let sitePath = 'public'; let sitePath = 'public/v2';
let indexView = 'views/index.html'; let indexView = 'index.html';
const listView = 'views/list.html'; const listView = 'views/list.html';
process.env.NODE_ENV = process.env.NODE_ENV || 'dev'; process.env.NODE_ENV = process.env.NODE_ENV || 'dev';
if (process.env.NODE_ENV === 'prod') { if (process.env.NODE_ENV === 'prod') {
isProduction = true; isProduction = true;
sitePath = 'live'; sitePath = 'public/v2';
indexView = 'dist/index.html'; indexView = 'index.html';
config.webhost = 'http://nurl.co/'; config.webhost = 'http://nurl.co/';
} }
@ -37,7 +37,7 @@ app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ 'extended': true })); app.use(bodyParser.urlencoded({ 'extended': true }));
app.use(express.static(path.join(__dirname, sitePath))); app.use(express.static(path.join(__dirname, sitePath)));
app.use(favicon(`${__dirname }/live/favicon-16x16.png`)); // app.use(favicon(`${__dirname }/live/favicon-16x16.png`));
app.all('/*', (req, res, next) => { app.all('/*', (req, res, next) => {
// CORS headers // CORS headers
@ -62,9 +62,13 @@ app.get('/admin/list', function(req, res) {
function postShort(req, res) { function postShort(req, res) {
const longUrl = req.body.url; const longUrl = req.body.url;
let shortUrl = ''; let shortUrl = '';
console.log('Shortening...', longUrl);
// check if url already exists in database // check if url already exists in database
Url.findOne({ 'long_url': longUrl }, (err, doc) => { Url.findOne({ 'long_url': longUrl }, (err, doc) => {
if(err)
console.error('findone error', err);
if (doc) { if (doc) {
shortUrl = config.webhost + base58.encode(doc._id); shortUrl = config.webhost + base58.encode(doc._id);
@ -116,6 +120,17 @@ app.post('/api/v1/shorten', postShort);
app.get('/api/v1/list', getList); app.get('/api/v1/list', getList);
app.get('/:encoded_id', getEncodedID); app.get('/:encoded_id', getEncodedID);
// Old pre letsencrypt
/*
const server = app.listen(config.port, () => { const server = app.listen(config.port, () => {
logger.info(`Server listening on port ${config.port}`); logger.info(`Server listening on port ${config.port}`);
}); });
*/
if (require.main === module)
app.listen(config.port, () => {
logger.info(`Server listening on port ${config.port}`);
});
// Instead do export the app:
module.exports = app;

1
greenlock.d/config.json Normal file
View File

@ -0,0 +1 @@
{ "sites": [{ "subject": "nurl.co", "altnames": ["nurl.co"] }] }

6276
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "url-shortener", "name": "nUrl",
"version": "1.0.0", "version": "1.0.1",
"description": "A NodeJS + Express + MongoDB based URL shortener", "description": "A NodeJS + Express + MongoDB based URL shortener",
"main": "app.js", "main": "app.js",
"scripts": { "scripts": {
@ -13,6 +13,7 @@
"compression": "^1.7.0", "compression": "^1.7.0",
"express": "^4.13.3", "express": "^4.13.3",
"express-favicon": "^2.0.0", "express-favicon": "^2.0.0",
"greenlock-express": "^4.0.3",
"mongoose": "4.2.9" "mongoose": "4.2.9"
}, },
"devDependencies": { "devDependencies": {
@ -26,23 +27,6 @@
"eslint-plugin-react": "^6.10.3", "eslint-plugin-react": "^6.10.3",
"eslint-plugin-standard": "^2.1.1", "eslint-plugin-standard": "^2.1.1",
"eslint-watch": "^3.0.1", "eslint-watch": "^3.0.1",
"gulp": "^3.9.1",
"gulp-autoprefixer": "^3.1.1",
"gulp-babel": "^6.1.2",
"gulp-cache": "^0.4.6",
"gulp-concat": "^2.6.1",
"gulp-cssnano": "^2.1.2",
"gulp-google-webfonts": "0.0.14",
"gulp-html-replace": "^1.6.2",
"gulp-htmlmin": "^3.0.0",
"gulp-inject": "^4.2.0",
"gulp-jshint": "^2.0.4",
"gulp-jsmin": "^0.1.5",
"gulp-rename": "^1.2.2",
"gulp-sass": "^3.1.0",
"gulp-scss": "^1.4.0",
"gulp-strip-debug": "^1.1.0",
"gulp-uglify": "^2.1.2",
"jshint": "^2.9.5", "jshint": "^2.9.5",
"log4js": "^2.3.3" "log4js": "^2.3.3"
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2040
public/v2/build/bundle.js Normal file

File diff suppressed because it is too large Load Diff

BIN
public/v2/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

66
public/v2/global.css Normal file
View File

@ -0,0 +1,66 @@
html, body {
position: relative;
width: 100%;
height: 100%;
}
body {
color: #333;
margin: 0;
padding: 8px;
box-sizing: border-box;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}
a {
color: rgb(0,100,200);
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:visited {
color: rgb(0,80,160);
}
label {
display: block;
}
input, button, select, textarea {
font-family: inherit;
font-size: inherit;
padding: 0.4em;
margin: 0 0 0.5em 0;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 2px;
}
input:disabled {
color: #ccc;
}
input[type="range"] {
height: 0;
}
button {
color: #333;
background-color: #f4f4f4;
outline: none;
}
button:disabled {
color: #999;
}
button:not(:disabled):active {
background-color: #ddd;
}
button:focus {
border-color: #666;
}

18
public/v2/index.html Normal file
View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<title>nUrl</title>
<link rel='icon' type='image/png' href='/favicon.png'>
<link rel='stylesheet' href='/global.css'>
<link rel='stylesheet' href='/build/bundle.css'>
<script defer src='/build/bundle.js'></script>
</head>
<body>
</body>
</html>

18
server.js Normal file
View File

@ -0,0 +1,18 @@
'use strict';
var app = require('./app.js');
require('greenlock-express')
.init({
'packageRoot': __dirname,
'configDir': './greenlock.d',
// contact for security and critical bug notices
'maintainerEmail': 'martind2000@gmail.com',
// whether or not to run at cloudscale
'cluster': false
})
// Serves on 80 and 443
// Get's SSL certificates magically!
.serve(app);

1005
sourceArticle.html Normal file

File diff suppressed because one or more lines are too long