Giter VIP home page Giter VIP logo

haste-server's Introduction

Important announcement:

Check here what you need to know.

.
.
.

Haste

Haste is an open-source pastebin software written in node.js, which is easily installable in any network. It can be backed by either redis or filesystem, and has a very easy adapter interface for other stores. A publicly available version can be found at hastebin.com

Major design objectives:

  • Be really pretty
  • Be really simple
  • Be easy to set up and use

Haste works really well with a little utility called haste-client, allowing you to do things like:

cat something | haste

which will output a URL to share containing the contents of cat something's STDOUT. Check the README there for more details and usages.

Tested Browsers

  • Firefox 8
  • Chrome 17
  • Safari 5.3

Installation

  1. Download the package, and expand it
  2. Explore the settings inside of config.js, but the defaults should be good
  3. npm install
  4. npm start (you may specify an optional <config-path> as well)

Settings

  • host - the host the server runs on (default localhost)
  • port - the port the server runs on (default 7777)
  • keyLength - the length of the keys to user (default 10)
  • maxLength - maximum length of a paste (default 400000)
  • staticMaxAge - max age for static assets (86400)
  • recompressStaticAssets - whether or not to compile static js assets (true)
  • documents - static documents to serve (ex: http://hastebin.com/about.com) in addition to static assets. These will never expire.
  • storage - storage options (see below)
  • logging - logging preferences
  • keyGenerator - key generator options (see below)
  • rateLimits - settings for rate limiting (see below)

Rate Limiting

When present, the rateLimits option enables built-in rate limiting courtesy of connect-ratelimit. Any of the options supported by that library can be used and set in config.js.

See the README for connect-ratelimit for more information!

Key Generation

Phonetic

Attempts to generate phonetic keys, similar to pwgen

{
  "type": "phonetic"
}

Random

Generates a random key

{
  "type": "random",
  "keyspace": "abcdef"
}

The optional keySpace argument is a string of acceptable characters for the key.

Storage

File

To use file storage (the default) change the storage section in config.js to something like:

{
  "path": "./data",
  "type": "file"
}

where path represents where you want the files stored.

File storage currently does not support paste expiration, you can follow #191 for status updates.

Redis

To use redis storage you must install the redis package in npm, and have redis-server running on the machine.

npm install redis

Once you've done that, your config section should look like:

{
  "type": "redis",
  "host": "localhost",
  "port": 6379,
  "db": 2
}

You can also set an expire option to the number of seconds to expire keys in. This is off by default, but will constantly kick back expirations on each view or post.

All of which are optional except type with very logical default values.

If your Redis server is configured for password authentification, use the password field.

Postgres

To use postgres storage you must install the pg package in npm

npm install pg

Once you've done that, your config section should look like:

{
  "type": "postgres",
  "connectionUrl": "postgres://user:password@host:5432/database"
}

You can also just set the environment variable for DATABASE_URL to your database connection url.

You will have to manually add a table to your postgres database:

create table entries (id serial primary key, key varchar(255) not null, value text not null, expiration int, unique(key));

You can also set an expire option to the number of seconds to expire keys in. This is off by default, but will constantly kick back expirations on each view or post.

All of which are optional except type with very logical default values.

MongoDB

To use mongodb storage you must install the 'mongodb' package in npm

npm install mongodb

Once you've done that, your config section should look like:

{
  "type": "mongo",
  "connectionUrl": "mongodb://localhost:27017/database"
}

You can also just set the environment variable for DATABASE_URL to your database connection url.

Unlike with postgres you do NOT have to create the table in your mongo database prior to running.

You can also set an expire option to the number of seconds to expire keys in. This is off by default, but will constantly kick back expirations on each view or post.

Memcached

To use memcache storage you must install the memcached package via npm

npm install memcached

Once you've done that, your config section should look like:

{
  "type": "memcached",
  "host": "127.0.0.1",
  "port": 11211
}

You can also set an expire option to the number of seconds to expire keys in. This behaves just like the redis expirations, but does not push expirations forward on GETs.

All of which are optional except type with very logical default values.

RethinkDB

To use the RethinkDB storage system, you must install the rethinkdbdash package via npm

npm install rethinkdbdash

Once you've done that, your config section should look like this:

{
  "type": "rethinkdb",
  "host": "127.0.0.1",
  "port": 28015,
  "db": "haste"
}

In order for this to work, the database must be pre-created before the script is ran. Also, you must create an uploads table, which will store all the data for uploads.

You can optionally add the user and password properties to use a user system.

Google Datastore

To use the Google Datastore storage system, you must install the @google-cloud/datastore package via npm

npm install @google-cloud/datastore

Once you've done that, your config section should look like this:

{
  "type": "google-datastore"
}

Authentication is handled automatically by Google Cloud service account credentials, by providing authentication details to the GOOGLE_APPLICATION_CREDENTIALS environmental variable.

Amazon S3

To use Amazon S3 as a storage system, you must install the aws-sdk package via npm:

npm install aws-sdk

Once you've done that, your config section should look like this:

{
  "type": "amazon-s3",
  "bucket": "your-bucket-name",
  "region": "us-east-1"
}

Authentication is handled automatically by the client. Check Amazon's documentation for more information. You will need to grant your role these permissions to your bucket:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "s3:GetObject",
                "s3:PutObject"
            ],
            "Effect": "Allow",
            "Resource": "arn:aws:s3:::your-bucket-name-goes-here/*"
        }
    ]
}

Docker

Build image

docker build --tag haste-server .

Run container

For this example we will run haste-server, and connect it to a redis server

docker run --name haste-server-container --env STORAGE_TYPE=redis --env STORAGE_HOST=redis-server --env STORAGE_PORT=6379 haste-server

Use docker-compose example

There is an example docker-compose.yml which runs haste-server together with memcached

docker-compose up

Configuration

The docker image is configured using environmental variables as you can see in the example above.

Here is a list of all the environment variables

Storage

Name Default value Description
STORAGE_TYPE memcached Type of storage . Accepted values: "memcached","redis","postgres","rethinkdb", "amazon-s3", and "file"
STORAGE_HOST 127.0.0.1 Storage host. Applicable for types: memcached, redis, postgres, and rethinkdb
STORAGE_PORT 11211 Port on the storage host. Applicable for types: memcached, redis, postgres, and rethinkdb
STORAGE_EXPIRE_SECONDS 2592000 Number of seconds to expire keys in. Applicable for types. Redis, postgres, memcached. expire option to the
STORAGE_DB 2 The name of the database. Applicable for redis, postgres, and rethinkdb
STORAGE_PASSWORD Password for database. Applicable for redis, postges, rethinkdb .
STORAGE_USERNAME Database username. Applicable for postgres, and rethinkdb
STORAGE_AWS_BUCKET Applicable for amazon-s3. This is the name of the S3 bucket
STORAGE_AWS_REGION Applicable for amazon-s3. The region in which the bucket is located
STORAGE_FILEPATH Path to file to save data to. Applicable for type file

Logging

Name Default value Description
LOGGING_LEVEL verbose
LOGGING_TYPE= Console
LOGGING_COLORIZE= true

Basics

Name Default value Description
HOST 0.0.0.0 The hostname which the server answers on
PORT 7777 The port on which the server is running
KEY_LENGTH 10 the length of the keys to user
MAX_LENGTH 400000 maximum length of a paste
STATIC_MAX_AGE 86400 max age for static assets
RECOMPRESS_STATIC_ASSETS true whether or not to compile static js assets
KEYGENERATOR_TYPE phonetic Type of key generator. Acceptable values: "phonetic", or "random"
KEYGENERATOR_KEYSPACE keySpace argument is a string of acceptable characters
DOCUMENTS about=./about.md Comma separated list of static documents to serve. ex: \n about=./about.md,home=./home.md

Rate limits

Name Default value Description
RATELIMITS_NORMAL_TOTAL_REQUESTS 500 By default anyone uncategorized will be subject to 500 requests in the defined timespan.
RATELIMITS_NORMAL_EVERY_MILLISECONDS 60000 The timespan to allow the total requests for uncategorized users
RATELIMITS_WHITELIST_TOTAL_REQUESTS By default client names in the whitelist will not have their requests limited.
RATELIMITS_WHITELIST_EVERY_SECONDS By default client names in the whitelist will not have their requests limited.
RATELIMITS_WHITELIST example1.whitelist,example2.whitelist Comma separated list of the clients which are in the whitelist pool
RATELIMITS_BLACKLIST_TOTAL_REQUESTS By default client names in the blacklist will be subject to 0 requests per hours.
RATELIMITS_BLACKLIST_EVERY_SECONDS By default client names in the blacklist will be subject to 0 requests per hours
RATELIMITS_BLACKLIST example1.blacklist,example2.blacklist Comma separated list of the clients which are in the blacklistpool.

Author

John Crepezzi [email protected]

License

(The MIT License)

Copyright © 2011-2012 John Crepezzi

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

Other components:

  • jQuery: MIT/GPL license
  • highlight.js: Copyright © 2006, Ivan Sagalaev
  • highlightjs-coffeescript: WTFPL - Copyright © 2011, Dmytrii Nagirniak

haste-server's People

Contributors

bridawson avatar brunosaboia avatar c0rn3j avatar dependabot[bot] avatar emillen avatar grampajoe avatar gwemox avatar hawur avatar j3parker avatar joeykrim avatar klasafgeijerstam avatar konstrybakov avatar leopere avatar lidl avatar lockszmith-gh avatar mcarneiro avatar meseta avatar naftis avatar nebulabc avatar pangeacake avatar passthemayo avatar razzeee avatar rdil avatar sebastiansterk avatar seejohnrun avatar szepeviktor avatar tfausak avatar wohlstand avatar yuimarudev avatar zaeleus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

haste-server's Issues

Use basicAuth

Would it be difficult to implement connect's basicAuth, to provide static user/password access to the hastebin server?

Why do pastes on hastebin.com regularly disappear after ~24 hours?

In http://hastebin.com/about.md it says that

Pastes will stay for 30 days from their last view. They may be removed earlier
and without notice.

I know there is a exceptional clause, however I don't think I ever had a paste that lasted this long. They ususally are deleted one or two days after.

I love the site for its simplicity, just open the site, ctrl-v, ctrl-s, ctrl-l, ctrl-c and you have a url. Potentially modify the url extension and paste it anywhere you like. I have not yet found a page where it is this easy and transparent to create pastes.

I would love if pastes lasted more than one or two days before they get deleted. They don't have to be permanent at all, but this time is barely enough and only works for quick conversations. I can't use it for emails for example because I don't know if the recipient will read it in time. Please do something about this. Or, if you can't do anything, you should probably change that part of the about.md to indicate that pastes are deleted way earlier than 30 days.

Twitter shortcut key poorly chosen

The default keyboard shortcut for Twitter submission (Ctrl-t) collides with the fairly common shortcut to create a new tab in several browsers.

If I didn't have a popup blocker, I would constantly be tweeting about things I really do not want to share.

Please choose an accelerator that tries to avoid the common shortcuts in browsers.

IE 11 support

I'd like to see Internet Explorer 11 support in Hastebin.

Show a list of past texts

Would be great to show a list of past texts right under the icons, so we could have an history to navigate.

@seejohnrun suggested to store it on HTML5 storage and I liked it.

There could be an extra attribute on the texts like an user id or username so you could populate the local storage once you move between computers

subdirectory with nginx proxypass

How would you use haste-server in a sub-directory? I can use it in the root of the WWW using proxypass to remove to port from the URL. Though if i try to use it in a sub-directory like location /haste problems start appearing.

Support to modify baseurl

I'm setting up hastebin on a server with other services, I'd like to proxy it through httpd to be exposed at /haste or something like that but it doesn't look like hastebin supports this.

Are there any plans to incorporate an option to set the baseurl? Currently hastebin expects to be running at /

hastebin.com is down

Right now the error message is
"
Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.

If you are the application owner, check your logs for details.
"

I assume this has to do with hosting, but just to be sure its worth checking those logs ...

Multiple documents loading problem

Here is the thing : I putted multiple static documents in my config, but there's only the latest loaded, 3 times !

info: listening on localhost:7777
info: connected to memcached on localhost:11211
info: loaded static document name=rss-feeds, path=./rss-feeds.opml
info: loaded static document name=rss-feeds, path=./rss-feeds.opml
info: loaded static document name=rss-feeds, path=./rss-feeds.opml
warn: document not found key=about
warn: document not found key=statusnet
verbose: retrieved document key=rss-feeds

My config is :

"documents": {
"about": "./about.md",
"statusnet": "./statusnet.php",
"rss-feeds": "./rss-feeds.opml"
}

Am I doing it right ? :/

Error connecting to redis

I followed the instructions (download, extract, edit config.js if needed, npm install, npm start), but maybe redis wasn't installed properly?

stdout:

blha303@irc:~/haste-server$ npm start

> [email protected] start /home/blha303/haste-server
> node server.js

info: configuring redis
info: compressed application.js into application.min.js
info: loading static document name=about, path=./about.md
info: listening on 0.0.0.0:7777
error: error connecting to redis index 2 error=undefined
npm ERR! [email protected] start: `node server.js`
npm ERR! `sh "-c" "node server.js"` failed with 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is most likely a problem with the haste package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node server.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls haste
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 2.6.18-308.el5.028stab099.3
npm ERR! command "nodejs" "/usr/bin/npm" "start"
npm ERR! cwd /home/blha303/haste-server
npm ERR! node -v v0.8.16
npm ERR! npm -v 1.1.69
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /home/blha303/haste-server/npm-debug.log
npm ERR! not ok code 0

Contents of npm-debug.log

0 info it worked if it ends with ok
1 verbose cli [ 'nodejs', '/usr/bin/npm', 'start' ]
2 info using [email protected]
3 info using [email protected]
4 verbose read json /home/blha303/haste-server/package.json
5 verbose run-script [ 'prestart', 'start', 'poststart' ]
6 info prestart [email protected]
7 info start [email protected]
8 verbose unsafe-perm in lifecycle true
9 silly exec sh "-c" "node server.js"
10 silly sh,-c,node server.js,/home/blha303/haste-server spawning
11 info [email protected] Failed to exec start script
12 error [email protected] start: `node server.js`
12 error `sh "-c" "node server.js"` failed with 1
13 error Failed at the [email protected] start script.
13 error This is most likely a problem with the haste package,
13 error not with npm itself.
13 error Tell the author that this fails on your system:
13 error     node server.js
13 error You can get their info via:
13 error     npm owner ls haste
13 error There is likely additional logging output above.
14 error System Linux 2.6.18-308.el5.028stab099.3
15 error command "nodejs" "/usr/bin/npm" "start"
16 error cwd /home/blha303/haste-server
17 error node -v v0.8.16
18 error npm -v 1.1.69
19 error code ELIFECYCLE
20 verbose exit [ 1, true ]

Specify syntax highlighting

Syntax highlighting isn't perfect, and often fails to detect the language being used. An option to specify it would be great.

Max files size

What is the default max size of log file you can paste, and what si the maximum possible value I can push this to ? Our team has to pass around a lot of log files for troubleshooting and this would work great, but its pretty comment for logs in question to be 30-40,000 lines

Backup / Restore?

what is the best way to backup your paste's ? We find our selves routinely using them for logging in tickets and would like to add some way to backup and restore paste's if at all possible

Apache proxy connection

I'm using Apache to proxy the requests from port 7777 to 80.

[error] (111)Connection refused: proxy: HTTP: attempt to connect to 127.0.0.1:7777 (127.0.0.1) failed
[error] ap_proxy_connect_backend disabling worker for (127.0.0.1)

Here is my proxy config :

<VirtualHost *:80>
    ServerAdmin root
    ServerName bin.postblue.info

    <IfModule mod_proxy.c>
        ProxyVia On
        ProxyRequests Off
        ProxyPass / http://127.0.0.1:7777/
        ProxyPassReverse / http://127.0.0.1:7777/
        ProxyPreserveHost on
        <Proxy *>
            AllowOverride All
            Order allow,deny
            allow from all
        </Proxy>
    </IfModule>
</VirtualHost>

Is there anyone else who have such a problem ?

highlight line

from email:

"""
hold be nice to add functionality to allow the specification of a line in the url
(example: http://hastebin.com/ruguxarori#12)

this would display the text at the specified line and highlight it.

Thanks and great job!
"""

JSONP support

It would be great if haste-server supported JSONP, so that JavaScript-based clients could interact with it.

Hastebin rocks - thanks for creating this project!

Offer raw text if javascript is disabled

Some people have javascript disabled by default, and the result is an empty page.
Would be great to see the raw version instead along with note about the awesome features they would get with javascript.

./about.md shows javascript block of code only

./about.md shows javascript block of code only.

When i visited /about i saw the raw markdown, but when i added the .md extension, it looks like it codeblocked the header of the page and showed that instead.

Certain text input crashes browser tab when attempting to save new hastebin

If you enter this text into hastebin and attempt to save it:

INFO 08-20 09:45:51,627 [main] SLF4JDemo.java,19 | marked 17 blah_blah_blah_blah completed for customerId=42 between Thu Jul 31 19:00:00 CDT 2014 and Mon Aug 04 19:00:00 CDT 2014
ERROR 08-20 09:45:51,631 [main] SLF4JDemo.java,24 | failed to mark blah_blah_blah_blah complete for customerId=42 between Thu Jul 31 19:00:00 CDT 2014 and Mon Aug 04 19:00:00 CDT 2014

it will completely lock up the browser tab. I suspect there is some parsing/sanitization logic that is stuck in an infinite loop...

Weird one! :-)

Can't create paste with "??" in contents

To reproduce:

  1. Enter ?? as the pasted text (alone or with more text).
  2. Try to save it.
  3. Observe a red "undefined" error.

Something is actually saved if you check server logs (in one of my cases, jQuery1707589711453765631_1328643245761)...but not the actual data.

Running ca9d4c1; also seen on hastebin.com.

Not loading up on EC2

Do I have to do anything special to the host/port configurations on EC2 ? I have opened up the port I intend to use (8080) and I am successfully running the server.
However when I connect to www.hardikr.com:8080 it just gives me a 404.. Is there some sort of security development/production measure I have to remove ?

Again, thanks for a wonderful OSS project!

FileDocumentStore has no method md5

OK, I have tried all 3 ways of getting Haste up and running - files, redis and memcached! All three of them give some error. Here is the one for file :

info: compressed application.js into application.min.js
info: listening on localhost:7777

/home/ubuntu/code/node/haste-server/lib/document_stores/file.js:28
var fn = _this.basePath + '/' + _this.md5(key);
                                        ^
TypeError: Object [object Object] has no method 'md5'
at Object.oncomplete (/home/ubuntu/code/node/haste-server/lib/document_stores/file.js:28:45)

It is strange because file.js has an md5 method explicitly defined for the object FileDocumentStore.

favicon

add a favicon to the site

IPv6 Support

How can I have the server bind to both v4 and v6 addresses or at minimum bind to an IPv6 address?

Activate syntax highlighting automatically

Instead of highlighting the paste after a save, the highlighting should kick in after you've typed a few lines. Additionally you should be able to set the programming language in the case it can not be detected or is wrongly detected.

Support for key naming schemes

It'd be nice if key names were able to be generated with different methods, much like how pwgen (man page) has phonetic generation and others. If you don't have a way of sending the link to yourself or writing it down (e.g., pasting some information to retrieve when you get back to your desk), it can be difficult to remember a purely random key.

line numbering

add line numbering. This should be in edit mode and in final mode, and should show the number of lines along with the main content. Scrollable also

Syntax Error?

Whenever i try to start NPM, it shows me i should do node server.js

node server.js

undefined:26
{
^
SyntaxError: Unexpected token {
at Object.parse (native)
at Object. (/home/kvm3/haste/haste-server/server.js:11:19)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3

My server.js (nothing changed!)

var http = require('http');
var url = require('url');
var fs = require('fs');

var winston = require('winston');
var connect = require('connect');

var DocumentHandler = require('./lib/document_handler');

// Load the configuration and set some defaults
var config = JSON.parse(fs.readFileSync('./config.js', 'utf8'));
config.port = process.env.PORT || config.port || 7777;
config.host = process.env.HOST || config.host || 'localhost';

// Set up the logger
if (config.logging) {
try {
winston.remove(winston.transports.Console);
} catch(er) { }
var detail, type;
for (var i = 0; i < config.logging.length; i++) {
detail = config.logging[i];
type = detail.type;
delete detail.type;
winston.add(winston.transports[type], detail);
}
}

// build the store from the config on-demand - so that we don't load it
// for statics
if (!config.storage) {
config.storage = { type: 'file' };
}
if (!config.storage.type) {
config.storage.type = 'file';
}

var Store, preferredStore;

if (process.env.REDISTOGO_URL && config.storage.type === 'redis') {
var redisClient = require('redis-url').connect(process.env.REDISTOGO_URL);
Store = require('./lib/document_stores/redis');
preferredStore = new Store(config.storage, redisClient);
}
else {
Store = require('./lib/document_stores/' + config.storage.type);
preferredStore = new Store(config.storage);
}

// Compress the static javascript assets
if (config.recompressStaticAssets) {
var jsp = require("uglify-js").parser;
var pro = require("uglify-js").uglify;
var list = fs.readdirSync('./static');
for (var i = 0; i < list.length; i++) {
var item = list[i];
var orig_code, ast;
if ((item.indexOf('.js') === item.length - 3) &&
(item.indexOf('.min.js') === -1)) {
dest = item.substring(0, item.length - 3) + '.min' +
item.substring(item.length - 3);
orig_code = fs.readFileSync('./static/' + item, 'utf8');
ast = jsp.parse(orig_code);
ast = pro.ast_mangle(ast);
ast = pro.ast_squeeze(ast);
fs.writeFileSync('./static/' + dest, pro.gen_code(ast), 'utf8');
winston.info('compressed ' + item + ' into ' + dest);
}
}
}

// Send the static documents into the preferred store, skipping expirations
var path, data;
for (var name in config.documents) {
path = config.documents[name];
data = fs.readFileSync(path, 'utf8');
winston.info('loading static document', { name: name, path: path });
if (data) {
preferredStore.set(name, data, function(cb) {
winston.debug('loaded static document', { success: cb });
}, true);
}
else {
winston.warn('failed to load static document', { name: name, path: path });
}
}

// Pick up a key generator
var pwOptions = config.keyGenerator || {};
pwOptions.type = pwOptions.type || 'random';
var gen = require('./lib/key_generators/' + pwOptions.type);
var keyGenerator = new gen(pwOptions);

// Configure the document handler
var documentHandler = new DocumentHandler({
store: preferredStore,
maxLength: config.maxLength,
keyLength: config.keyLength,
keyGenerator: keyGenerator
});

// Set the server up with a static cache
connect.createServer(
// First look for api calls
connect.router(function(app) {
// get raw documents - support getting with extension
app.get('/raw/:id', function(request, response, next) {
var skipExpire = !!config.documents[request.params.id];
var key = request.params.id.split('.')[0];
return documentHandler.handleRawGet(key, response, skipExpire);
});
// add documents
app.post('/documents', function(request, response, next) {
return documentHandler.handlePost(request, response);
});
// get documents
app.get('/documents/:id', function(request, response, next) {
var skipExpire = !!config.documents[request.params.id];
return documentHandler.handleGet(
request.params.id,
response,
skipExpire
);
});
}),
// Otherwise, static
connect.staticCache(),
connect.static(__dirname + '/static', { maxAge: config.staticMaxAge }),
// Then we can loop back - and everything else should be a token,
// so route it back to /index.html
connect.router(function(app) {
app.get('/:id', function(request, response, next) {
request.url = request.originalUrl = '/index.html';
next();
});
}),
connect.static(__dirname + '/static', { maxAge: config.staticMaxAge })
).listen(config.port, config.host);

winston.info('listening on ' + config.host + ':' + config.port);

Long first few lines are partially hidden by logo

if a paste contains a long first few lines (greater than the width of the screen - logo width), the end of each line will be hidden by the Hastebin logo and controls. It can be seen by using raw text, but otherwise you are unable to scroll out to the end.

Trying to think of a graceful way of showing the full line.. Perhaps somehow setting the page width wider than that will allow scrolling past the end of the line so that it will show fully on the left side of the logo? Or some sort of wrap or other way of being able to see it?

Error 127

Dagon@two:/www/haste-server-master$ npm start

[email protected] start /www/haste-server-master
node server.js

sh: 1: node: not found
npm ERR! [email protected] start: node server.js
npm ERR! sh "-c" "node server.js" failed with 127
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is most likely a problem with the haste package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node server.js
npm ERR! You can get their info via:
npm ERR! npm owner ls haste
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.11.0-12-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "start"
npm ERR! cwd /www/haste-server-master
npm ERR! node -v v0.10.15
npm ERR! npm -v 1.2.18
npm ERR! code ELIFECYCLE
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /www/haste-server-master/npm-debug.log
npm ERR! not ok code 0

Add ability to edit a document using a random private key

Hello,

I think editing a document instead of creating a new copy can be very interesting.
Once a new document is saved, the user can edit the document whenever he wants using a random generated private key.

http://hastebin.com/mugehequvi.rb

To edit the file, a user can go to : http://hastebin.com/mugehequvi.rb/private_key
or : http://hastebin.com/edit/mugehequvi.rb/private_key

For the gem, a user can type : 'cat file' | haste -k private_key

Thanks!

Questions about development

Hi, I hope this is an ok forum for these questions. :)

  • It seems launching server.js re-minifies application.js. Is that correct? Or, in other words, If I change application.js, what do I need to do to make sure the changes are correctly reflected in .min.js?
  • On that note, it actually seems like application.min.js should be .gitignored, since it's a build artifact and prone to meaningless merge conflicts. Shouldn't it?
  • If I want a feature and I'm willing to do the work, should I just make it happen and send a pull request, or run it by you first?

Thanks for making this! It works real nice.

Line numbers don't align correctly

http://hastebin.com/pexobuqicu.avrasm :
linenumbers It begins quite well, but in the end it is messed up.

I'm using latest version, with Google Chrome and this has bugged me for a few months already. It seems to add 1 or 2 pixels everytime (or just randomly? I haven't investigated this too much)

I'm not sure when this happens, but it doesn't happen if I only add some random text, like asdasdasdasdasd \n asdasdasda \n asdasdad \n and so on. It happens with code.

edit: hmm, I noticed that it doesn't happen with .hs extensions, it has something to do with the syntax hilighting

Chromium grabs the shortcuts

Chromium Version 24.0.1312.52 (175374) grabs shortcuts. For example if i press the ctrl +n new window opens. But haste should create new file

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.